how to async/await redux-thunk actions?

The Promise approach export default function createUser(params) { const request = axios.post(‘http://www…’, params); return (dispatch) => { function onSuccess(success) { dispatch({ type: CREATE_USER, payload: success }); return success; } function onError(error) { dispatch({ type: ERROR_GENERATED, error }); return error; } request.then(success => onSuccess, error => onError); }; } The async/await approach export default function createUser(params) … Read more

How to listen for specific property changes in Redux store after an action is dispatched

You may use Redux’s mapStateToProps and connect with React’s componentDidUpdate(prevProps, prevState, snapshot) hook. So basically your code could look like this: const mapStateToProps = (state) => ({ specificProperty: state.specificProperty, // any props you need else }); class YourComponent extends React.Component { render() { // render your component } componentDidUpdate(prevProps, prevState, snapshot) { if (prevProps.specificProperty !== … Read more

What is the difference between redux-thunk and redux-promise?

redux-thunk allows your action creators to return a function : function myAction(payload){ return function(dispatch){ // use dispatch as you please } } redux-promise allows them to return a promise : function myAction(payload){ return new Promise(function(resolve, reject){ resolve(someData); // redux-promise will dispatch someData }); } Both libraries are useful if you need to dispatch action async … Read more

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

Why do we need middleware for async flow in Redux?

What is wrong with this approach? Why would I want to use Redux Thunk or Redux Promise, as the documentation suggests? There is nothing wrong with this approach. It’s just inconvenient in a large application because you’ll have different components performing the same actions, you might want to debounce some actions, or keep some local … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)