React Flashcards
What is React?
A JavaScript library for building user interfaces or UI components
What is a React element?
React element is something that describes DOM nodes and properties virtually
How do you mount a React element to the DOM?
root.render(element)
What is JSX?
a syntax extension to JavaScript that produces React “elements”
Why must the React object be imported when authoring JSX in a module?
Because the React library must be in scope from the JSX code in order to make calls to React.createElement
So the JSX can be converted into valid JavaScript that a browser can understand.
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
using babel loader with plugin @babel/plugin-transform-react-jsx
What is a React component?
a JavaScript class or function that optionally accepts inputs i.e. properties(props) and returns a React element that describes how a section of the UI (User Interface) should appear.
How do you define a function component in React?
By writing a JavaScript function that accepts props as a single argument and returns a React element
How do you mount a component to the DOM?
ReactDOM.render( )
What are props in React?
They are objects used to pass data between react components
How do you pass props to a component?
<Component>
</Component>
How do you write JavaScript expressions in JSX?
wrap it in { } curly braces
How do you create “class” component in React?
class ComponentName extends React.Component {
render ( ) {
return….
}
}
How do you access props in a class component?
this.props
What is the purpose of state in React?
State is an object where property values belonging to a component are stored. When state changes, the component re-renders