React Flashcards
What is JSX?
a syntax extension to JS allow us to write declarative inside js files (such as HTML).
Why must the React object be imported when authoring JSX in a module?
because JSX is part of React library
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
by installing devDependencies -> @babel/plugin-transform-react-jsx
What is a React component?
JS functions
How do you define a function component in React?
function function_name (props as parameter) {
return JSX element[s]
}
How do you mount a component to the DOM?
by calling render of root object and passing in JSX elements/function components
What are props in React?
Parameters for React function component
{ object }
How do you pass props to a component?
through attribute keys and value ->
<Function></Function>
How do you write JavaScript expressions in JSX?
{ JS expression }
How do you create “class” component in React?
class className extends React.Component {
render() {
return //codes
}
//other codes
}
How do you access props in a class component?
using this.props.//
What is the purpose of state in React?
object that hold information that influences the output render(), state is managed within the component
How to you pass an event handler to a React element?
by binding it. this.EventHandler.bind(this)
also add it as attribute onto the JSX element[s]
What are controlled components?
an element whose value is controlled by react
What two props must you pass to an input for it to be “controlled”?
value & onChange