Replies: 1 comment 2 replies
-
Alright, so what I did is wrap the formMachine in a function and passed the initial context to it: export const formMachine = (initialContext) =>
createMachine({
context: {
value: initialContext,
},
initial: "editing",
states: {
editing: {
on: {
CHANGE: assign({
values: (ctx, e) => ({
...ctx.values,
[e.key]: { value: e.value },
}),
}),
CLEAR: assign({ values: initialContext }),
},
},
},
}); But I don't want the whole initialContext object to be saved in the database, I only want to save what I changed. Any help will be appreciated. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a formMachine and I want to initialize the context with data persisted in a database.
useMachine(formMachine, { context: { values: valuesFromDb() } })
Now, I want to add values to a
newValues
object in anonChange
action so I can send these updates to the database.I have a couple of problems:
newValues
value to the initialvalue
object so that the changes are reflected in the UIdiscard
.newValues
object to the GraphQL mutation, not the whole initial object (this should be as easy as sending thenewValues
context value).Beta Was this translation helpful? Give feedback.
All reactions