React.js Flashcards
What is React.js?
A JavaScript library for building user interfaces.
What is a React element?
It is an object that describes what the actualDocument Object Model(DOM)element should look like.
What does the createElement( ) method do?
It creates & returns a new React element of the given type.
What is JSX?
JSX is a syntax extension to JavaScript that’s generally used with React to describe what the DOM should look like. It looks like an HTML tag.
Why must the React object be imported when authoring JSX in a module?
Since JSX compiles into calls toReact.createElement from Babel, theReactlibrary must also always be in scope from your JSX code.
What is a React component?
Components areindependent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML. Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.
How do you define a function component in React?
First, you define a function with a name (first letter of name should be capitalized). Then we have a parameter called props that represent the property. Inside the code block we have code that returns JSX code.
How do you mount a component to the DOM?
By using the render method of the ReactDOM object.
How you install React & ReactDOM as a dependency?
npm install react + npm install react-dom
Fill in the blank.
Fundamentally, JSX just provides _____ for the React.createElement( ) function.
Syntactic sugar
How do you put a JavaScript expression in JSX?
You put a JavaScript expression inside the curly braces in JSX inside the JSX tags.
For example:
function getGreeting(user) { if (user) { return <h1> Hello, {formatName(user)}! </h1>; }
How should you name React elements and why should name it that way?
First letter should be uppercased or else React will think of it as an HTML tag and it will be converted as a string from Babel.
What are props in React?
Props arearguments passed into React components. Props (which stands for properties) is an object and it contains all of thepropspassed to the child component.
How do you pass props to a component?
You create a react element in the component, then assign the prop name to a value.
How do you write JavaScript expressions in JSX?
You can write any JavaScript expression by surrounding it with{ }.