- It is state container.It means it stores the state of our application.
- useContext
- useReducer
- why then use redux, not react hooks: Redux released 2015 when these hooks was not available.
- React-redux is a library that provides bindings to use React and redux together in an application.
- shop= store: hold the state of our application
- Intentions to BUY_CAKE = Action : describes what happened or tell what to do
- shopkeeper= Reducer : Ties the store adn actions together or tell how to do
- First principle:
- The state of our whole application is stored in an object tree within a single store.
- Maintain our application state in a single object which would be managed by the Redux store.
- Second principle:
- The only way to change the state is to emit an action, an object describing what happened.
- To update the state of our app, we need to let Redux know about that with an action
- Not allowed to directly update the state object
- Third principle:
- To specify how the state tree is transformed by actions, you write pure reducers or pure javascript functions.
- only 1 store for one app.Store is readonly, for updating store, we can only do it through reduce
- The only way our application can interact with the store
- Carry some information from your app to the redux store
- Action is plain javascript objects and action creator is a pure javascript function which return action
- Have a 'type' property that indicates the type of action being performed.
- Action creator is a function which create the action
- Specify how the app's state changes in response to actions sent to the store
- Function that accepts state and action as arguments and returns the next state of the application .
- (previousState,action)=> newState
- combineReducers function: it helps to use multiple reducers in redux store
- It is suggested way to extend Redux custom functionality.
- Provides a third-party extension point between dispatching an action, and the moment it reaches the reducer.
- Use middleware for logging, crash reporting, performing asynchronous tasks etc.
- To use API call to fetch data from an end point
- redux-thunk: it helps us to make async code.
- It helps us to return a function instated of default action creator return object
-
note: the redux-thunk function doesn't need to be a pure function.This function also can dispatch action.The function receives dispatch method as it's argument
-
Way to make async action creators
- install axios: Request to an API end point
- install redux-thunk: To define async action creators which is a middleware
- Holds application state
- Allows access to state via getState()
- Allows state to be updated via dispatch(action)
- Registers listener via subscribe(listener).I figured subscribe wasn't really necessary if I was using React-Redux and connect
- Handles unregistering of listeners via the function returned by subscribe(listener)
- it helps to connect redux with react component. it has two function parameters (mapStateToProps, mapDispatchToProps)
- If we want to use only mapDispatchToProps, then we can pass 'null' value as another argument in connect function
Redux hooks: these are alternative to connect.Subscribe to store and dispatch actions without connect()
- useSelector(): it is equivalent to mapStateToProps
- useDispatch(): it is equivalent to mapDispatchToProps
- note: need to explore more to know
- why need ...state like this and mean why need to copy
- is actions creator payload necessary or when and why use payload in action creator
- How redux-thunk dispatch method works as an argument or Can I name different:yes
- different ways to write initial state in reducers such as object, array, string etc.
- if I define initial state as object will I my array become object of array
- why need to call arrow function and what is prevState
- need to know about switch case condition well
- why need to write arrow function to call function inside jsx in react
- How ownProps works in mapStateToProps and mapDispatchToProps in connect function
- conditional rendering and List rendering
- what is the significant of having the key prop when rendering a list of elements
- what is the potential bug that you can introduce when using index as a key?
- Class component's lifecycle methods
- legacy code
- Order of invocation and a brief description of when you'd use each one of them
- Context API
- React hooks : why need hooks
- useState,useEffect and useContext
- useEffect: how it works with class lifecycle methods
- Optimization : prevent unnecessary re-render in app
- Pure components
- memo
- useMemo and useCallback
- How share logic across components?
- Higher order components
- Render props pattern
- Custom hooks
- what are some of the packages that you use along with React or React ecosystem?
- Styling
- Routing
- Form handling
- State management
- create-react-app or Custom webpack config
- what is redux?
- How do you decide whether to choose Context API or Redux?
- explain different parts of redux such as store,action, action-creator, reducers
- How the control flows between these different parts?
- What exactly does the connect function do from the react-redux library?
- what mapStateToProps and mapDispatchToProps actually do?
- In a reducer, why should you return a new object as state and not modify the existing state?