Pros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/await

In redux-saga, the equivalent of the above example would be export function* loginSaga() { while(true) { const { user, pass } = yield take(LOGIN_REQUEST) try { let { data } = yield call(request.post, ‘/login’, { user, pass }); yield fork(loadUserData, data.uid); yield put({ type: LOGIN_SUCCESS, data }); } catch(error) { yield put({ type: LOGIN_ERROR, error … Read more

‘TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string. Received type undefined’

To fix this issue simply upgrade react-scripts package (check latest version with npm info react-scripts version): Replace in your package.json “react-scripts”: “^3.x.x” with “react-scripts”: “^3.4.1” (or the latest available version) (optional for some) Delete your node_modules folder Run npm install or yarn install Some people reported that this issue was caused by running npm audit … Read more

Uncaught Invariant Violation: Too many re-renders. React limits the number of renders to prevent an infinite loop

I suspect that the problem lies in the fact that you are calling your state setter immediately inside the function component body, which forces React to re-invoke your function again, with the same props, which ends up calling the state setter again, which triggers React to call your function again…. and so on. const SingInContainer … Read more

React: Parent component re-renders all children, even those that haven’t changed on state change

If a parent component is updated, does React always update all the direct children within that component? No. React will only re-render a component if shouldComponentUpdate() returns true. By default, that method always returns true to avoid any subtle bugs for newcomers (and as William B pointed out, the DOM won’t actually update unless something … Read more

Cannot update a component while rendering a different component warning

This warning was introduced since React V16.3.0. If you are using functional components you could wrap the setState call into useEffect. Code that does not work: const HomePage = (props) => { props.setAuthenticated(true); const handleChange = (e) => { props.setSearchTerm(e.target.value.toLowerCase()); }; return ( <div key={props.restInfo.storeId} className=”container-fluid”> <ProductList searchResults={props.searchResults} /> </div> ); }; Now you can … Read more

Trace why a React component is re-rendering

If you want a short snippet without any external dependencies I find this useful componentDidUpdate(prevProps, prevState) { Object.entries(this.props).forEach(([key, val]) => prevProps[key] !== val && console.log(`Prop ‘${key}’ changed`) ); if (this.state) { Object.entries(this.state).forEach(([key, val]) => prevState[key] !== val && console.log(`State ‘${key}’ changed`) ); } } Here is a small hook I use to trace updates to … Read more