@@ -6,22 +6,22 @@ import { Component, Form } from "effect-fc"
|
||||
import { useContext, useFork } from "effect-fc/hooks"
|
||||
|
||||
|
||||
const LoginFormSchema = Schema.Struct({
|
||||
const RegisterFormSchema = Schema.Struct({
|
||||
email: Schema.String,
|
||||
password: Schema.String.pipe(Schema.minLength(3)),
|
||||
})
|
||||
|
||||
class LoginForm extends Effect.Service<LoginForm>()("LoginForm", {
|
||||
class RegisterForm extends Effect.Service<RegisterForm>()("RegisterForm", {
|
||||
scoped: Form.make({
|
||||
schema: LoginFormSchema,
|
||||
initialValue: { email: "", password: "xxx" },
|
||||
schema: RegisterFormSchema,
|
||||
initialValue: { email: "", password: "" },
|
||||
})
|
||||
}) {}
|
||||
|
||||
class LoginFormComponent extends Component.makeUntraced(function* LoginFormComponent() {
|
||||
const form = yield* LoginForm
|
||||
const emailInput = yield* form.useInput(["email"])
|
||||
const passwordInput = yield* form.useInput(["password"])
|
||||
class RegisterPage extends Component.makeUntraced(function* RegisterPage() {
|
||||
const form = yield* RegisterForm
|
||||
const emailInput = yield* form.useInput({ path: ["email"], defaultValue: "" })
|
||||
const passwordInput = yield* form.useInput({ path: ["password"], defaultValue: "" })
|
||||
|
||||
yield* useFork(() => Stream.runForEach(form.latestValueSubscribable.changes, Console.log), [])
|
||||
|
||||
@@ -63,15 +63,15 @@ class LoginFormComponent extends Component.makeUntraced(function* LoginFormCompo
|
||||
}) {}
|
||||
|
||||
|
||||
const FormRoute = Component.makeUntraced(function* FormRoute() {
|
||||
const context = yield* useContext(LoginForm.Default)
|
||||
const LoginFormComponentFC = yield* Effect.provide(LoginFormComponent, context)
|
||||
const RegisterRoute = Component.makeUntraced(function* RegisterRoute() {
|
||||
const context = yield* useContext(RegisterForm.Default)
|
||||
const RegisterRouteFC = yield* Effect.provide(RegisterPage, context)
|
||||
|
||||
return <LoginFormComponentFC />
|
||||
return <RegisterRouteFC />
|
||||
}).pipe(
|
||||
Component.withRuntime(runtime.context)
|
||||
)
|
||||
|
||||
export const Route = createFileRoute("/form")({
|
||||
component: FormRoute
|
||||
component: RegisterRoute
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user