In RecoilJS
docs, there is an example how to handle asynchronous data queries, but it's only about get data.
Let say I have a simple state:
const accountState = atom({
key: "accountState",
default: {
id: "",
name: "",
}
});
And a component which is a register form:
const RegisterForm = () => {
return (
<form>
<input type="text" name="username" />
<button type="submit">Register</button>
</form>
)
}
The posted data is in FormData
. After successfully created new account, the server will send a response that contains id
and name
of the account.
{
"id": "abcdef123456",
"name": "example"
}
This response data will be set as a new state of accountState
.
How can I handle the process in RecoilJS
?