React Flashcards
Learn about react fundamental s
Which if the following is used when adding an event to a button in react?
A onClick
B. onclick
onClick
What is the convention of defining a class in react?
Use lowercase for class the class extends component You normally states to access or modify properties values.
What is the correct method of declaring a class name for a JSX element?
Use className
How do you add and output dynamic content within a react function.
Use the curly braces and or props
What is a restriction faced in react JSX
Class is reserved
You advised to only have one route element per component.
Can you change states directly?
No, it is immutable. Use setState to change state and notify dom
Can you change states directly?
No, it is immutable. Use setState to change state and notify dom
True or false. The function element found in setState merges the changes with the old state.
False
The function used in the hook usestate does not merge. It creates a new state.
What are the two ways in can modify the Dom in react?
state taken from react component
and props which use Hooks
What is a example of react Hook?
useState
What is the difference in the way states and hooks handle other state data?
In classes that use state , any changes made are merged with previous state.
In functions props which use Hooks, the state creates new state so you need to include this change in function that changes state.
What is React.createElement?
Method for rendering JSX , Takes the following arguments: an element which is rendered to the Dom, configuration other wise a object, then children or what will be nested in side the elements.
How can one render iteration in react
JavaScript provides a array method Array.protoype.map which can be used render an array of objects.
Syntax let new array = array.map( funct callback( current Value, [, index [, array]] { return element of new array }[ , thisArg])
const arrayx = [ 1 , 2 , 3 , 4 ] const map1 = arrayx.map( x => x + 1 )
When is it not ideal to use map()
When you are not using the returning array , not returned a value from callback.
How would you attempt to handle JavaScript errors beyond your control , like server request.
You can wrap your code using error boundaries class. This return a message in production mode.
How can you run locally scoped class names for CSS styles that are easy to identify without adding complexity with naming conventions.
You can use CSS modules .
React V2,, + -require you add modules in the name using [name]. module.css
Older version require ejection and modifications
What are error boundaries?
Error boundaries are react components that handle JavaScript errors by catching them in their child components tree. Allowing you to log errors and display fall back UI rather than let the UI crash.
A component becomes a errorBoundary when it defines either or both getDerivedStateFromError or componentDidCatch lifecycle methods.
How does React monitor changes in state in the mapping of React arrays
Map has key which can provide unique identifier for each element in the state array.
What are the benefits of spread operators in Rest state management?
Spread operators can be used when setting state in order to avoid directly updating the original state object.
What is the purpose of the restructuring in useState and hooks?
useState uses restructuring to split array into current state and the function to set state.
What are the benefits of using arrow functions in react components callbacks.
Arrow functions have a key feature that shares same lexical ‘ this ‘ as surrounding code. It does not require the literal use of binding with ‘this’ operators unlike function.
Snipet “rce” means
Create a customisation react class component.
Snipet “rafcp” means
Create a react function component with props
Snipet rafce means
Create a react arrow function component