React & libraries Flashcards
What’s the top level of your app, and what params does it take?
() => {
}
What does the top-level Router component do?
Updates its state when its history attr emits an event.
<router></router>
What attributes can you pass to ?
\
What arguments does Redux’s createStore() take?
createStore((state, action) => state, [initialState])
creates a store from a reducer and an initial state
What is Redux’s store API?
subscribe, dispatch, getState
What’s the signature for a middleware passed to applyMiddleware?
({ getState, dispatch }) => next => action
Each middleware should call next() with action… or maybe not, or maybe at a different time.
Previous middlewares will receive the next middleware’s “dispatch” function. The last will receive the original dispatch method.
You want to compose async behavior by dispatching a thunk. What should the thunk’s signature be?
(dispatch, getState) => Promise
body: fetch(url).then(data => {}, error => {}), and dispatch actions with the data.
compose? (not most recent major version of Redux)
Just a functional utility, composes funs left to right.
Use compose to combine store enhancers into a more powerful createStore.
compose(applyMiddleware(…middlewares), devTools(), persistState(), createStore)
React Router: what should you use instead of a tags?
link to=””
I want to pass multiple components to a <route>?</route>
Name them!
<route></route>
Manipulating class names:
Which package do you import?
What function does it bring in?
What attribute do you apply to the React component?
classnames
classNames
className
Redirect attrs?
<redirect></redirect>
<route></route>
<!-- `/profile/123` -> `/about/123` -->
<redirect></redirect>
<!-- `/profile/me` -> `/about-user/123` -->
<redirect></redirect>
If a Route has no path…?
It’ll look for path matches among children, and render them inside {this.props.children} of the parent component.