Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs Rewrite] Meta-Issue: Understanding Redux section #3600

Open
8 tasks
markerikson opened this issue Oct 29, 2019 · 6 comments
Open
8 tasks

[Docs Rewrite] Meta-Issue: Understanding Redux section #3600

markerikson opened this issue Oct 29, 2019 · 6 comments
Labels
Milestone

Comments

@markerikson
Copy link
Contributor

markerikson commented Oct 29, 2019

This is a tracking issue for all work related to creating a new "Understanding Redux" section

Goal

Pasting from my original writeup in #3313 :

This section has several objectives:

  • Teach the "prerequisites" needed for Redux, including JS array methods, immutability, etc
  • Teach people how to "think in Redux" (multiple reducers listening to one action, treating actions more as events than "setters", etc)
  • Some details on how Redux works internally
  • Info on when you should use Redux, and why Redux patterns exist. (This should mostly be cribbed from Dan's "You Might Not Need Redux", my "Idiomatic Redux: The Tao of Redux" posts, and Justin Falcone's "What's So Great About Redux?").

Tasks

  • "Background Concepts" section
    • Outline content
    • Move material from "Structuring Reducers"
  • "Thinking in Redux" section
    • Outline content
  • "How does Redux Work?" section
    • Outline content
  • "History and Design" section
    • Outline content
@wgao19
Copy link
Contributor

wgao19 commented Oct 30, 2019

Would love to work on these also. But I feel these sections are more subjective than others so maybe will work on them later. Putting up a few resource links first

@markerikson
Copy link
Contributor Author

markerikson commented Dec 7, 2019

Two great resources on how and why to model actions as events:

  • Dillon Mulroy - "Event Driven Redux": video / slides
  • Yazan Alaboudi - Our Redux Anti-Pattern: A Guide to Scalability: video / slides

Also:

@markerikson
Copy link
Contributor Author

Totally can't forget @modernserf 's great post on What's So Great about Redux?.

@markerikson
Copy link
Contributor Author

markerikson commented Dec 30, 2020

A very good summary of the "business logic" approach:

https://twitter.com/FwardPhoenix/status/952972062058074112

"Can it be done with just dispatch arguments?" -> action creator.
"Can it be done with previous state and action?" -> reducer
"Can it be done from just state?" -> probably a component.

So "where does the business logic lives" -> everywhere.

Thoughts on teaching the "multiple reducers responding" pattern:

https://twitter.com/dai_shi/status/1184230104613810177

When I teach Redux, I find many beginners misunderstand that pattern. They are surprised when I tell that pattern is possible and even recommended.
One of the reasons why this happens, I think, is combineReducers. It's in core and almost all examples use it

@markerikson
Copy link
Contributor Author

markerikson commented Jan 8, 2023

More bookmarks that could be useful:

@markerikson
Copy link
Contributor Author

"Modeling actions as events":

https://www.reddit.com/r/reactjs/comments/oa5pwe/why_is_it_so_difficult_to_modify_a_deeply_nested/h3ip5gj/

When we say "model actions as events", it implies a few different things:

  • Naming: "somethingHappened", vs "setThing"
  • Mindset: it's not "setters at a distance", it's "broadcast this info, any code that cares can do something with that info"
  • Code layout: having more logic in a reducer, vs always calculating the entire state first -> sticking it in the action -> doing return action.payload or state.someValue = action.payload
  • Handling logic: it's fine for many reducers to update themselves independently in response

None of that goes away with RTK - it's more about a mental model than specific syntax.

These aren't absolutes, and in some ways it's a hard mindset shift to grasp. And, tbh, most Redux actions will only ever be handled by one slice reducer in practice. But, I've seen folks writing separate setFieldX, setFieldY actions for every individual field in some slice, and that's definitely not the right mental approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants