- Does a component re-render when its props change?
Yes
- Does a component re-render when a parent's props change?
Yes
- How can we ensure a component re-renders only when its props change?
Wrap the component in the memo function
- What function prop would we use to add a keydown event listener?
onKeyDown
- A component has the following props interface:
interface Props {
name: string;
active: boolean;
}
How can we destructure the props parameter and default active to true?
We can do the following:
export const myComponent: FC<Props> = ({ name, active = true }) => ( ... )
- Let's say we have a state called dateOfBirth. How can we type this to be Date?
We can do the following:
const [dateOfBirth, setDateOfBirth] = useState<Date>(undefined);
- How could we use the useEffect hook to call a synchronous function called getItems when a piece of state called category changes, passing in category to getItems?
We can do the following:
useEffect(() => {
getItems(category);
}, [category]);