-
-
Save Kelin2025/e4f3488922f0246b0144419dc7361ea9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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