React App Best Practices Flashcards
What is the purpose of container components?
Manage the logic:
- Generate side effects at different life cycles
What is the purpose of presentation components?
Display the data
What is the purpose of render props?
To have components that share the same logic but have different presentation (huge win)
When should you consider using render prop?
When you are coding similar components to ones you have already made. Don’t try to use render before noticing code repetition, otherwise you might not get the abstraction right and mess up your code more than if you had two very similar components.
What are generator functions?
Generators are functions which can be exited and later re-entered. Their context (variable bindings) will be saved across re-entrances.
How to declare a generator function?
function* generatorName() { … }
What is Redux-Saga
Redux-Saga is a library that aims to make handling side effects in React/Redux applications easier & better.
Being a Redux middleware, what can Redux-Saga do?
Handle all the normal Redux actions and dispatch actions.
What is a Redux-Saga similare to?
It’s like a seperate thread in your application that’s solely responsible for side effects.
How does Redux-Saga middleware work?
By utilizing generator functions and handling the calling of next() and using yields whenever it needs to.
By convention, what are the two categories of Sagas?
Watchers & Workers.
What is the role of watcher sagas?
Watch for dispatched actions and fork a worker on every action.
What is the role of worker sagas?
Will handle the action and terminate
What are effect creators?
Functions which return JavaScript objects (called effects) composed of properties that tells Redux-Saga middleware how to handle these effects.
What does the call() effect creator does?
It calls the function passed a parameter (if it is an aync function, it will wait for it to end) and returns the result.