But it gets the job done, and sometimes the most expedient option wins.Īt the end of the day, “done” is better than “perfect. That feels like it should be purely an API concern. Personally, I’m not crazy about Option 4 (passing it from a React component), because I don’t like having to thread an auth token through components. Sometimes that’s not where you need it, though, and it might feel strange to mix a Redux concern with your generic utility code. Using this function we don't have to make. You need to set the state on the updated array, not on what splice returns. However, splice will change the contents of the array it's called on. If no elements were removed, splice will return an empty array. Option 2 (getState in a thunk) is fine if it makes sense to access your data inside a thunk. Hey Guys,In this video we're going to learn about the createSlice() function in Redux-Toolkit. splice () returns an array of elements that have been removed from the array. I like Option 1 (export the store) for its simplicity, and I’ve used it in the past – but only on an app that didn’t need server rendering.Īt some point, our import became troublesome because of a circular dependency, and we switched to something closer to Option 3 (intercepting an action). How to slice JSON data in ReactJS Ask Question Asked 5 years ago Modified 5 years ago Viewed 3k times 2 I have made 2 components 1)Content.js 2)Pagination. Import store from './store' export function getProtectedThing () ) export connect(mapStateToProps)(ItemList) Which Option Is Best?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |