Skip to content

Instantly share code, notes, and snippets.

@Kelin2025
Last active March 19, 2019 20:42
Show Gist options
  • Save Kelin2025/e4f3488922f0246b0144419dc7361ea9 to your computer and use it in GitHub Desktop.
Save Kelin2025/e4f3488922f0246b0144419dc7361ea9 to your computer and use it in GitHub Desktop.
import React from 'react'
import { useStore } from 'effector-react'
import { createStore, createEvent } from 'effector'
// events.js
const emailChanged = createEvent('Email changed')
const passwordChanged = createEvent('Password changed')
const submitPressed = createEvent('Submit pressed')
// stores.js
const $email = createStore('')
.on(emailChanged, (_, next) => next)
const $password = createStore('')
.on(passwordChanged, (_, next) => next)
const $authForm = createStoreObject({ email: $email, password: $password })
// EmailInput.js
const EmailInput = () => {
const email = useStore($email)
return <input value={email} onChange={evt => emailChanged(evt.target.value)} />
}
// PasswordInput.js
const PasswordInput = () => {
const password = useStore($password)
return <input value={password} onChange={evt => passwordChanged(evt.target.value)} />
}
// AuthForm.js
const AuthForm = () => {
return <form onSubmit={submitPressed}>
<EmailInput />
<PasswordInput />
<button>Submit</button>
</form>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment