React Flashcards
how to define a html/css class in react
className=”string”;
className={ expression }
basic render function?
return (
<div></div>
);
import react and hooks
import React, {useEffect, useState, createRef, etc.. } from “react”;
set up a basic state variable and setter
const [varName, setVarName] = useState();
set a default state when setting up a state variable
const [varName, setVarName] = useState(‘default val’);
update a state variable using the setter
setVarName(‘new value’);
set up a useEffect handler function
useEffect(() => {
actionHandler();
});
//or: },[list, of, functions, to, watch]
use [] so it only activates on first mount
create a Ref to a dom element
functionally
let textInput = useRef(null);
using:
{
props.setEmail(textInput.current.value)
}}
in render:
…
ref={textInput} />
what does ‘useEffect return’ equal?
useEffect return is mostly equal to componentWillUnmount