Basics Flashcards
What is React?
React is a declarative, efficient, and flexible JaveScript library for building user interfaces. It lets you compose complex UIs from small and isolated pieces of code called “components”.
What do components do and what happens when data changes?
Q: What do components do and what happens when data changes?
We use components to tell React what we want to see on the screen. When our data changes, React will efficiently update and re-render our components.
What does a component take as parameters and what does it return?
Q: What does a component take as parameters and what does it return?
A component takes in parameters called props(short for properties) and returns a hierarchy of views to display via the render method.
What does the render method return?
Q: What does the render method return?
The render method returns a description of what you want to see on the screen. React takes the description and displays the result. In particular, render returns a React element, which is a lightweight description of what to render.
What can you put inside JSX braces?
Q: What can you put inside JSX braces?
You can put any JavaScript expressions within braces inside JSX. Each React element is a JavaScript object that you can store in a variable or pass around in your program.
How do you pass data from the parent component to the child component?
By using the props object. Passing props is how info flows in React apps, from parents to children.
How do components “remember “ things?
Q: How do components “remember “ things?
By using state.
How can React components have state?
Q: How can React components have state?
BY setting this.state in their constructors. this.state should be considered private to a React component that it’s defined in.
What do you always need to do when defining the constructor of a subclass?
You always need to call super(props) when defining the constructor of a subclass. All React component classes that have a constructor should start with a super(props) call
What does React Dev Tools do?
The React Dev Tools let you check the props and state of your React components.
What does the Components tab do in React Dev Tools?
Q: What does the Components tab do in React Dev Tools?
The Components tab allows you to inspect the component tree.
Why lift up state?
To collect data from multiple children, or to have two child components communicate with each other, you need to declare the shared state in their parent component. The parent component can pass the state back down to the children by using props: this keeps the child components in sync with each other and with the parent component.