I\'m developing a course scheduling application in react, and I\'m using it as a chance to learn redux. There\'s a browse menu (implemented as the Browse component) that I\'
Using connect
on child components has the following advantages:
Your parent component need not bother about connect
ing all the props required by its children even though the parent itself is not using the prop.
Child components become more reusable, and easily maintainable.
Avoids passing down props blindly from parent to children. If the Child
requires a considerable number of props, people don't want to explicitly pass only the required props, instead they tend to do this inside the parent: <Child {...this.props} />
.
Use connect
and you know what your Component is getting.
You don't have to repeat propTypes
definitions in parent and children.
Business logic is:
Views should:
Pull prepared data from state and/or business logic functions
Show or hide UI based on data
Simplify UI components so that they are small, reusable, and easily maintainable
Get props through connect
from a business logic function.
Business logic functions are small reusable functions that input data and output modified data. If they are small, they can be easily reused and modified. Business logic functions should be pure. Because business logic functions are often reused, they work best when memoized. In some languages these are called getters or selectors.
To streamline memoization, you may use reselect library. It’s a very simple as it only does two things: memoization and reusability. Take a look at the official API for more information on how it does that.
Advantages: