React.js Flashcards
What is a React component?
independent and reusable bits of code.
They serve the same purpose as JavaScript functions, but work in isolation and return HTML via a render() function.
How do you define a function component in React?
function functionName(props) { return ( jsx; ); }
How do you mount a component to the DOM?
ReactDOM.render(element, container)
element is a component ex)
container is usually a div with root
What are props in React?
“Props” is a special keyword in React, which stands for properties and is being used for passing data from one component to another.
How do you pass props to a component?
Use it as a parameter in the function component
How do you write JavaScript expressions in JSX?
In curly braces
How do you create “class” component in React?
class componentName extends React.component { render() { return { this.props.text }; } }
How do you access props in a class component?
this.props
What is the purpose of state in React?
To update state and change UI (re-render) accordingly
How do you pass an event handler to a React element?
{ this.state.isClicked ? ‘Thanks!’ : ‘Click Me!’}