POST action replaces entire data array (until refresh)
See original GitHub issueWhen I do a POST action, the entire array of data (this.state.kittens.data
below) is replaced by the new post data. When I do a browser refresh, the data is restored. Why?
reduxApi config:
export default reduxApi({
kittens: {
url: '/api/kittens/:id',
crud: true,
transformer: transformers.array,
options: {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}
}
}).use('fetch', adapterFetch(fetch));
POST action:
handleAdd (event) {
const newKitten = {
name: this.state.name,
};
this.props.dispatch(reduxApi.actions.kittens.post({}, { body: JSON.stringify(newKitten) }));
}
JSX:
<button onClick={this.handleAdd.bind(this)}>Add kitten</button>
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Array only gets data when I refresh the page - Stack Overflow
since I can't see the full picture but it seems like something isn't coming in properly from the .api file. Can you console.log(categoryName) ......
Read more >Refresh ag-Grid after a data change with React, Angular, Vue ...
This blogpost shows how to refresh ag-Grid after row adding/update/delete in all the popular web frameworks - Angular, React, VueJS.
Read more >Cheat Sheet for Updating Objects and Arrays in React State
This is a cheat sheet on how to do add, remove, and update items in an array or object within the context of...
Read more >How To Handle Async Data Loading, Lazy Loading, and Code ...
After the asynchronous function resolves, update an unordered list with the new information. Save and close the file. When you do the browser ......
Read more >Array.prototype.fill() - JavaScript - MDN Web Docs - Mozilla
The fill() method changes all elements in an array to a static value, from a start index (default 0) to an end index...
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
Good implementation 👍
Not sure if this is the right approach, but I solved it with a custom
transformer
:Also, I had to modify the server API to return the
_id
of the deleted item.Thankful for any suggestions on how to improve.