v20221114
{ num === 7 ? <img> : null }
{ num === 7 &&
<img>
}
const [piece of state, function of piece of state] = useState(initialValue);
const [count,setCount] = useState(count);
onClick={() => setCount(count + 1)};
//
const [calculator,setCalculator] = useState({ count }); //if you wanted calculator.count to update
onClick={() => setCalculator({...calculator,count:calculator.count + 1})};
import { useState } from "react";
function useToggle(initialVal = false) {
const [state,setState] = useState(initialVal);
const toggle = () => {
setState(!state);
};
return [state, toggle];
}
export default useToggle;
useEffect(() => {
document.title = `You clicked ${count} times`;
});
useEffect(() => {
document.title = `You clicked ${count} times`;
},[]);
useEffect(() => {
//do something only when number or year is changed
}, [number, year]);