react.js Flashcards
What is Webpack?
it is a “bundler” which basically gathers large amounts of code from js files and npm packages into a single or few files
What is the advantage of using Webpack (or a similar bundler)?
easier to download, remove unused code, makes the code obscure so it is hard for people to decipher
What is Babel?
it is a transpiler, which translates new code to an older version. so in babel it translates new es6 js code into an older version
What is the advantage of using Babel (or a similar transpiler)?
it allows you to write code in the newer version while still being able to work with older devices and systems
What is React?
javascript library used for building UIs for web apps
What is a React element?
it is a component, basically its code that is like a custom dom element
How do you mount a React element to the DOM?
by using ReactDOM.createRoot and root.render
What is JSX?
JavaScript XML is a language that allows developers to write HTML-like code inside of a JS code
How does React use JSX to render components?
by using babel to transform the JSX to JS
What is a React component?
a custom DOM element
How do you define a component in React?
by defining a function with a capital letter?
How do you mount a component to the DOM (or “render” a component)?
ReactDOM.render
What are props in React?
passing information to their child components
How do you use props in a component?
pass in the props as the parameter as a destructured object
How do you pass props to a component?
add attributes to the component
How do you write JavaScript expressions in JSX?
by enclosing them in {}
How do you pass an event handler to a React component?
as one of the props
What is the naming convention for event handlers?
having a “handle” prefix
(ex. handleClick)
What are some custom event handler props a component may wish to define?
onClick, onSubmit, onChange
What is the naming convention for custom event handler props?
having a “on” prefix
(ex. onClick)
What are hooks in React?
functions that lets you use states in components
What are the “Rules of Hooks”? (if necessary, re-read the “Pitfall” box in State)
hooks starting with use can only be called at the top level of your component or your own hook, you can’t call Hooks inside conditions, loops, or other nested functions
What is the purpose of state in React?
to manage data within components in between function calls
Why can’t we just maintain state in a local variable?
if it is in a local variable the variable resets after it is run, react doesn’t know that the component’s state has changed
What two actions happen when you call a state setter function?
the state is updated and then re-rendered
When does the local state variable get updated with the new value?
the next time the useState is called and it is re-rendered