r/reactjs • u/swyx • Jul 01 '18
Help Beginner's Thread / Easy Question (July 2018)
Hello! just helping out /u/acemarke to post a beginner's thread for July! we had almost 550 Q's and A's in last month's thread! That's 100% month on month growth! we should raise venture capital! /s
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. You are guaranteed a response here!
New to React? Free, quality resources here
- Read the new, official Getting Started page on the docs
- /u/acemarke's suggested resources for learning React and his React/Redux links list.
- Kent Dodds' Egghead.io course
- Tyler McGinnis' 2018 Guide
- Codecademy's React courses
Want Help on Code?
- Improve your chances of getting helped by putting a minimal example on to either JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new). Describe what you want it to do, and things you've tried. Don't just post big blocks of code.
- If you got helped, 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.
51
Upvotes
View all comments
Show parent comment
1
u/SelkiesTheEndless Jul 25 '18
Thanks, that makes sense. I was just doing some POC work and I think I came up with another way of asking the same question. I was looking at the example redux todo list application found here: https://redux.js.org/basics/example-todo-list https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/todos
Lets say we were to modify the application and add any another property to the redux store (username). Anytime we set the username would cause the VisibleTodoList container to run its mapsStateToProps. If the current filter is SHOW_ALL then TodoList would not re-render because it would always return the same array, the todos part of the State. BUT if SHOW_COMPLETED was selected every time we set the username TodoList would re-render because getVisibleTodos is returning using filter which returns a new copy of the array.
This was my "aha" moment earlier and I was trying to figure out how to properly derive data from the state that returns an array without bad re-renders. I think came up with two answers, add Reselect or use a custom sCU function.