React Study Questions
What is React.js?
- Open source JavaScript Library
- Used to build Single Page Applications
- Utilizes reusable components
- Helpful for dynamic user interfaces
Describe React Components.
- Can either be class or function.
- React elements that construct (make up) a react application
- Typcally return JSX
What is JSX?
- JavaScript XML, used to create React elements that resemble HTML elements
- Can only return one JSX element per component
- Can include embedded JS surrounded by
{}
- Cannot contain JS protected keywords (e.g.
for
,class
, etc)
Describe State and Props.
- State
- Data values that persist throughout the lifecycle of a component, and when change/updated, they trigger a component re-render
- Props
- Data values that are passed from parent component to child component
- State
How do you render a list in React, and how are keys involved?
- When rendering a list in react, use the .map() array method to return a new array of JSX elements, each of which having a unique key prop assigned to it
- Lists are arrays that can be returned to JSX as a list of JSX elements
Describe the Effect Hook.
- Will receive a callback function and dependency array. Calls the function after each render, but only if any of the values mentioned in the dependency array have changed.
- Example:
Explain React Router
- Allows for a react application to display many different views depending on the URL path.
- Install into a project with
npm install react-router-dom
- React Router comes with the following components:
- BrowserRouter
- Routes
- Route
- Link
- Example:
Describe React Router Hooks.
React Router comes with several react hooks useful for navigation
Navigate Hook
- Will return a function that will programmically navigate to a new route, causing a new component to be rendered
- Example:
Params Hook
- Will return an object with parsed URL parameter name/values
- Example:
Location Hook
- Will return an object with:
- pathname
- search queries
- state passed from navigation
- url hash values
- Will return an object with: