react-events-and-state Flashcards
1
Q
What is the purpose of state in React?
A
The purpose of state is to contain data or information about a component at any given time. This allows the user to control the
2
Q
How do you pass an event handler to a React element?
A
You specify a method of the “this” object and pass it into the event handler inside of the “render” method’s code block
ex. render() {
return (
< button onClick = { this.handleClick } >
{ this.state.isClicked ? ‘Thanks!’ : ‘Click Me!’ }
< / button >
);
}