JavaScript React Flashcards
What is React?
a framework that makes it easier to make reusable components. To make interactive code easier to write.
What is a React element?
React apps are made out of components. A component is a piece of the UI (user interface) that has its own logic and appearance. A component can be as small as a button, or as large as an entire page. A custom written DOM element.
How do you mount a React component to the DOM? or
How do you insert/render a component to the DOM tree?
What is JSX?
JSX stands for JavaScript XML.
JSX allows us to write HTML in React.
JSX makes it easier to write and add HTML in React.
How does React use JSX to render components?
What is a React component?
Reusable UI
React apps are made out of components. A component is a piece of the UI (user interface) that has its own logic and appearance. A component can be as small as a button, or as large as an entire page. A custom written DOM element.
How do you define a component in React?
a function whose name starts with a capital letter. the return should be JSX.
How do you mount a component to the DOM (or “render” a component)?
attach it to the root. calls the function when it sees it wrapped in <>. Takes the result of calling the function and puts it in the DOM.
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. But the important part here is that data with props are being passed in a uni-directional flow. ( one way from parent to child). Corresponds to attributes in HTML.
How do you use props in a component?
destructure the props object in the parameter. or use the props object as a parameter.
How do you pass props to a component?
in angle brackets, prop propertyname = value
in curly braces, call the component with arguments of values of the props.
How do you write JavaScript expressions in JSX?
You write JavaScript expressions in JSX inside curly braces. {JAVASCRIPT EXPRESSION}
How do you pass an event handler to a React component?
pass your event handler as a prop to your component
What is the naming convention for event handlers?
handleEvent() {
}
What are some custom event handler props a component may wish to define?
onClick, onSubmit, onChange, onMouseEnter, onMouseLeave,
What is the naming convention for custom event handler props?
onEventHandlerProps
What are hooks in React?
Hooks are special functions that are only available while React is rendering. They let you “hook into” different React features.
they start with use followed by an uppercase letter. ie useState.
What are the “Rules of Hooks”? (if necessary, re-read the “Pitfall” box in State)
Hooks—functions starting with use—can only be called at the top level of your components or your own Hooks. You can’t call Hooks inside conditions, loops, or other nested functions. You can only call them in react components and other hooks.
What is the purpose of state in React?
to update a local data.
state holds the data inbetween function calls.
Why can’t we just maintain state in a local variable?
it exists only within the block that it is declared in. Once that block ends, the variable is destroyed and its values lost”.
What two actions happen when you call a state setter function?
triggers react to rerender again. updates a cashe of the state variable.
When does the local state variable get updated with the new value?
on the re render.
How do controlled components differ from uncontrolled components?
controlled components parent is in control.???
uncontrolled components are controlled by the input itself.???
What are some advantages of using uncontrolled components?
you dont have to use useState. It is simpler, you can just grab the form data.
What are some advantages of using controlled components?
Ui and data are in sync, when you update the UI, the data is updated at the same time. Anytime you have 2 components interacting with each other is a good time to use it.???
Which style do you prefer?
What two props must you pass to an input for it to be “controlled”?
value and onChange