React Components Flashcards
What is a React.Component?
Is a simple javascript class that must be inherited to write a react component.
How parameters are sent to the component?
Via the props parameter
How to have the vscode html helpers even on javascript files?
By configuring the emmet settings.json to:
"emmet.includeLanguages": { "javascript": "html" }
What does the render method returns?
a React element
How to interpolate javascript in a JSX structure?
By the use of the curly brackets { }
What is the method that is always called when you create a react component?
render(){
}
How to do string interpolation on javascript?
the string needs to be defined with `` and the var with ${ }
alert(this is the flashcard no ${number}.
Where the react component keeps values to be used later on?
In the react’s superclass state property
What to do with the javascript class when you need to implement the constructor?
You need to call super(props) in order to call React’s constructor - normal oop
Should all react components’ constructor start with a super(props)?
Yes… All React component classes that have a constructor should start with a super(props) call.
What happens when you call setState in a react component?
It refreshes itself and also all the child components.
What is the React Developer Tools?
React Developer Tools is a tool that allows you to inspect a React tree, including the component hierarchy, props, state, and more. To get started, just open the Firefox devtools and switch to the “⚛️ Components” or “⚛️ Profiler” tab.
What is a controlled component?
Is when a component does not have its own state, instead it receives delegates to call and inform changes to the parent component.
What is immutability in React?
Is when instead of changing the object’s data, you create a new instance of object and replace the existing object with the updated one.
Why is immutability important?
Complex features become simpler (time travel) and also the change detection mechanism works best once the object instance changes (instead of its content only).
What is the main benefit of immutability?
The main benefit of immutability is that it helps you build pure components in React. Immutable data can easily determine if changes have been made which helps to determine when a component requires re-rendering.
What is a function component and what is the benefits of using one?
In React, function components are a simpler way to write components that only contain a render method.
When to use a function component?
When the component don’t have their own state…
Can a component change the props?
No, it can only change its own state.
What are the four ways to create a react component?
React.createClass (deprecated), extends React.Component, Function component and Arrow Functions…
What is a container component? What are common “attributes” of such component?
A component that has little to no markup. Tie other presentation components together. Knows about Redux. Stateful.
What is a presentation component? What are common “attributes” of such component?
Dumb. Full of markup. Receives data and actions via prop. does not know about Redux. Not stateful - just plain functions.
When is it a good idea to create a container component?
When the props a component received is not used and just passed down.