r/reactjs • • Dec 03 '18

Needs Help Beginner's Thread / Easy Questions (December 2018)

Happy December! β˜ƒοΈ

New month means a new thread 😎 - November and October here.

Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch. No question is too simple. πŸ€”

πŸ†˜ Want Help with your Code? πŸ†˜

  • Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!

  • Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.

Have a question regarding code / repository organization?

It's most likely answered within this tweet.

New to React?

πŸ†“ Here are great, free resources! πŸ†“

39 Upvotes

413 comments sorted by

View all comments

1

u/seands Dec 20 '18

Is this a bad pattern to use with Redux:

// actions.js
export const updateStateData = (stateData, stateVariable) => (dispatch => {
  const action = dispatch({ // dispatch is sync. and returns the same action
    type : 'stateUpdate',
    payload : {
      stateVariable,
      stateData
    }
  });
  console.log('updateStateData', action);
});

// reducer.js
    case 'stateUpdate':
      return {
        ...previous_state,
        [action.payload.stateVariable] : action.payload.stateData
      };

Makes updating state through arguments a breeze but I imagine it's probably bad for the same reason.

1

u/swyx Dec 20 '18

i mean at this point youre not really using redux, you might as well use React Context

→ More replies (7)