Question: Post data through API with RecoilJS
See original GitHub issueIn 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
?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Post data through API with RecoilJS - reactjs - Stack Overflow
The posted data is in FormData . After successfully created new account, the server will send a response that contains id and name...
Read more >CRUD with RecoilJS and remote API - Medium
RecoilJS is a modern state management library for React developed by the Facebook team. You may ask “Another one state management lib?
Read more >Asynchronous Data Queries - Recoil
Asynchronous Data Queries. Recoil provides a way to map state and derived state to React components via a data-flow graph. What's really powerful...
Read more >Limit of recoil and when to add or use extra library : r/reactjs
For example in one of my app, I have classic API calls and I build my state with async selectors which fetch the...
Read more >React + Recoil - Set atom state after async HTTP GET or ...
This is a quick example of how to set the state of a Recoil atom after sending an async HTTP GET or POST...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A followup to say that I’d love to see an async setter so that we could do something much more simple like this:
@adrianbw - Instead of an async post selector set, consider just using a setter for
YourAtom
fromuseSetRecoilState()
oruseRecoilCallback()
to provide a callback which can asynchronously set the atom with the response.