React.js Flashcards
What is React?
A JavaScript library for building user interfaces
What is a React element?
smallest building blocks of react - also describes what the DOM should look like
How do you mount a React element to the DOM?
using ReactDOM.render()
What is JSX (JavaScript XML)?
A syntax extension to JavaScript that provides a way to structure component rendering using syntax familiar to many developers
Why must React object be imported when authoring JSX in a module?
Importing React is necessary because Babel compiles JSX down to React.createElement() calls
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
Webpack will allow babel loader to identify JSX needs to compiled and you can use Babel loader to compile JSX and transform JSX plug-in is necessary for babel to know
What is a React component?
review again - React component is sth
How do you define a function component in React?
function with a return statement like JavaScript function definition
How do you mount a component to the DOM?
Using ReactDOM.render(, document.querySelector(‘#id’));
What are props in React?
review again - Props are properties that are basically kind of global variable or object
How do you pass props to a component?
review again - component name key = string or javascript expression
How do you write JavaScript expressions in JSX?
curly braces
How do you create “class” component in React?
with keyword class className extends keyword React.Component with render() method
How do you access props in a class component?
use this keyword
What is the purpose of state in React?
State is an object that determines how that component renders and behaves
How do you pass an event handler to a React element?
you pass an event handler via prop
What Array method is commonly used to create a list of React elements?
map()
What is the best value to use as a “key” prop when rendering lists?
IDs: The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys
What are controlled components?
example is input element - Controlled components are react are fully wired into it and pass in value prop and onChange components
What two props must you pass to an input for it to be “controlled”?
value and type and onChange