React/Redux Notes
Consider this...a cheat sheet.
REDUX STORE
- Redux is a pattern and library used to manage and update an application’s state through events called “actions”.
- It stores and tracks the global state, ensuring that it can only be manipulated in a predictable way. (controlled components?) Nope...actions via dispatch
- The store is a container that holds the application’s global state
DISPATCH
- Redux store method
- The only way to update the state is by calling store.dispatch() and pass in an action object
- This triggers the store to run its reducer function, makes the changes, and returns the new state
ACTIONS
- The source of data for the store.
- It carries a payload of information from the application to the store
- It must have a type (descriptive name for the action) that describes what kind of action was performed
- It is a plain JS object
REDUCER
- An event listener which handles events based on the action/event type it receives
- It is a function, receives current state and an action object, determines if and how to update the state, and returns a new state
- (state, action) => newState
STATE vs. PROPS
- State is a plain JS object that is managed within a component
- Starts with a default value when the component mounts
- Redux application state lives in the store
- state => like a variable declared in a function
- Props, short for properties, is a plain JS object that is passed to a component
- Received from a parent, immutable to the children receiving it
- props => like an argument passed to the function
- They both hold information that influences the output of render
THUNK
- Thunk is middleware that allows functions to be returned instead of plain JS action objects. This allows for delayed actions, like working with promises.
- Middleware is important because it prevents things like an action creator returning an action before data has been fetched.
PROVIDER
- A component that makes the react store available to any nested component.
- Components that need access to the store, do so by calling connect()
CONNECT
- Connects a React component to the Redux store
- React component -> receives data from the store and learns which functions it can use to dispatch actions to the store
- Returns a new, connected component class. DOES NOT modify the original.
STATELESS FUNCTION
- A function that can only render the data it receives. It DOES NOT manage or track changes to that data
CONTAINER vs. COMPONENT
- A Container is connected to redux store, by convention, and is supposed to make things work
- A component is supposed to be presentational. It only renders the data.
JSX
- JSX = JavaScript XML => is a syntax extension of JavaScript. Enables us to write HTML in React
SPREAD OPERATOR
- Provides a copy of all the elements inside something, like an array.
LIFECYCLE METHODS
- Special methods of the component class that run some code when a component mounts and unmounts.
- Mounts: when the component is rendered in the DOM for the first time
- Unmounts: when the DOM produced by the component is removed
DOM
- The data representation of the objects that comprise the structure and content of a document on the web.
CONDITIONAL vs. LIST RENDERING
- Conditional rendering is when one creates a new component that encapsulates some behavior and then renders that component and its logic in another component.
- List rendering takes some array and one can iterate through the values, or map a new array.
- Keys help react identify which items have changed
- Using indexes as keys can be problematic because data can change, if something gets deleted from the list, its index would be invalid and the element will have an unstable identity.
REACT.COMPONENT
- This gives an ES6 class access to useful React features such as lifecycle hooks and local state.
Constructor
- A special method used when objects created with the class keyword are initialized.
Super( )
- A method used to call the constructor of the parent class; usually React.Component
CLOSURE
- A function that remembers its lexical scope
- Lexical scope is the functions local memory as well its parents local memory
- Example:
- function x() {
- var a = 7
- function y() {
- console.log(a)
- }
- return y
- }
- Even when y is returned, it remembers the scope of its parent, x; and that is where it finds the value for a.
THIS
- A way of pointing to something in the program; provides context.
- Its value depends on when and how it is called.
- Example:
- function myFunc() {
- console.log(this)
- }
- // this is default to the window because there is nothing to the left of the period
- const obj = {
- bool: true,
- myFunc: myFunc,
- }
- obj.myFunc()
- // this is now an object because to the left of the period is obj

Thanks for stopping by 🙃️, BYE!