Chapter 3 – Getting Started with React and TypeScript

  1. Does a component re-render when its props change?

Yes

  1. Does a component re-render when a parent's props change?

Yes

  1. How can we ensure a component re-renders only when its props change?

Wrap the component in the memo function

  1. What function prop would we use to add a keydown event listener?

onKeyDown

  1. 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 }) => ( ... )
  1. 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);
  1. 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]);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.107.255