General React.js Flashcards
React.js is a framework, library or langauage?
Library
What does a React function look like?
function Welcome(props) { return <h1>Hello, {props.name}</h1>; }
What does a React component look like?
class Welcome extends React.Component { render() { return <h1>Hello, {this.props.name}</h1>; } }
What notation are React events written?
camelCase
Where do you bind events?
In the constructor
How are named modules imported? Default modules?
import defaultExport, { namedExport1, namedExport3, etc… } from ‘module’;
Difference b/w class component and function?
A class component requires you to extend from React.Component and create a render function which returns a React element. Class is required for states.
Why use class components?
When states are needed
How to pass states to a function?
If you need a state in your component you will either need to create a class component or you lift the state up to the parent component and pass it down the functional component via props.
What is preventDefault() event method?
- ## the default action that belongs to the event will not occur.
What does Redux Middleware do?
Provides the capability to run code after an action is dispatched, but before the reducer. e.g. 3rd party extension point, logging, aysnc API calls
What can middleware be used for?
-inspecting the action and state
- modify action
dispatch other actions
- stop actions from reaching reducers
What is Thunk?
A kind of middleware that subroutine used to inject an additional calculation in another subroutine; allows you to write action creators that return a function instead of an action; use Thunk to generator an API call to a server; used for complex synchronous logic (multiple/conditional dispatches)
What is a reducer?
Reducers specify how the application’s state changes in response to actions sent to the store.
Reducers calculate a new state given the previous state and an action
Pure function that computes the next state.
Predictable.
What are Redux Actions?
Payloads of information that send data from your application to your store.
They are the only information for the store. They are sent to the store using store.dispatch().
They are plain JS. They must have a type property that indicates the type of action being performed.
They are ‘what happened’.
What is the Redux Store?
The object that brings actions and reducers together.
The store:
- holds application state (tree);
- allows acces to state via getState();
- allows state to be updated via dispatch(action);
- registers listeners
- handles unregistered listeners
type Store = {
dispatch: Dispatch
getState: () => State
subscribe: (listener: () => void) => () => void
replaceReducer: (reducer: Reducer) => void
}
Only one store made using createStore()