React Flashcards
What is React?
JS library for building user interface
What is a React element?
What gets returned from components. An object that virtually describes the DOM nodes.
How do you mount a React element to the DOM?
render( ) method
What is JSX?
Syntax extension to JavaScript to describe what UI should look like.
Why must the React object be imported when authoring JSX in a module?
Because JSX works with react. It produces react elements.
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
@babel/plugin-transformed-react-jsx
What is a React component?
JS function or class that returns react elements
How do you define a function component in React?
Similar to JS
Define the function (parameters)
return JSX/React Elements
First letters of function name must be capitalized!
How do you mount a component to the DOM?
render( ) method
What are props in React?
An object in react
How do you pass props to a component?
Property key = value (similar to attribute/value in HTML)
How do you write JavaScript expressions in JSX?
{ }
How do you create “class” component in React?
Class keyword extends keyword React.Component
- with required render method
How do you access props in a class component?
this.props
What is the purpose of state in React?
Changes your elements
How to you pass an event handler to a React element?
On the react element (similar to attribute/value in HTML)
What are controlled components?
Can be input form element who’s value is controlled by React
What two props must you pass to an input for it to be “controlled”?
value and onChange
What Array method is commonly used to create a list of React elements?
map( ) method
What is the best value to use as a “key” prop when rendering lists?
ID - whatever uniquely identifies it
What does fetch() return?
A promise
What is the default request method used by fetch()?
GET
How do you specify the request method (GET, POST, etc.) when calling fetch?
2nd argument of the fetch method