#thedivisor#Add some logic to <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">Avatar</code> that uses the <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">person</code> and <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">size</code> props for rendering, and you’re done.#thedivisor#Now you can configure <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">Avatar</code> to render in many different ways with different props. Try tweaking the values!#thedivisor#Props let you think about parent and child components independently. For example, you can change the <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">person</code> or the <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">size</code> props inside <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">Profile</code> without having to think about how <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">Avatar</code> uses them. Similarly, you can change how the <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">Avatar</code> uses these props, without looking at the <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">Profile</code>.#thedivisor#You can think of props like “knobs” that you can adjust. They serve the same role as arguments serve for functions—in fact, props <em>are</em> the only argument to your component! React component functions accept a single argument, a <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">props</code> object:#thedivisor#Usually you don’t need the whole <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">props</code> object itself, so you destructure it into individual props.#thedivisor#<strong class="font-bold">Don’t miss the pair of <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">{</code> and <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">}</code> curlies</strong> inside of <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">(</code> and <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">)</code> when declaring props:#thedivisor#This syntax is called <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Unpacking_fields_from_objects_passed_as_a_function_parameter" target="_blank" rel="nofollow noopener noreferrer" class="inline text-link dark:text-link-dark border-b border-link border-opacity-0 hover:border-opacity-100 duration-100 ease-in transition leading-normal">“destructuring”</a> and is equivalent to reading properties from a function parameter:#thedivisor#If you want to give a prop a default value to fall back on when no value is specified, you can do it with the destructuring by putting <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">=</code> and the default value right after the parameter:#thedivisor#Now, if <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px"><Avatar person={...} /></code> is rendered with no <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">size</code> prop, the <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">size</code> will be set to <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">100</code>.#thedivisor#The default value is only used if the <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">size</code> prop is missing or if you pass <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">size={undefined}</code>. But if you pass <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">size={null}</code> or <code dir="ltr" class="inline text-code text-secondary dark:text-secondary-dark px-1 rounded-md no-underline bg-gray-30 bg-opacity-10 py-px">size={0}</code>, the default value will <strong class="font-bold">not</strong> be used.
#thedivisor#Add some logic to Avatar that uses the person and size props to render, and you’re done.#thedivisor#Now you can set up Avatar to show in many different ways using different props. Try changing the values!#thedivisor#Props allow you to think about parent and child components separately. For example, you can change the person or size props inside Profile without needing to worry about how Avatar uses them. Likewise, you can change how Avatar uses these props, without looking at Profile.#thedivisor#You can think of props like “knobs” that you can adjust. They work like arguments for functions—in fact, props are the only argument for your component! React component functions take one argument, a props object:#thedivisor#Usually you don’t need the whole props object, so you break it down into individual props.#thedivisor#Don’t forget the pair of { and } curlies inside of ( and ) when setting up props:#thedivisor#This syntax is called “destructuring” and is the same as getting properties from a function parameter:#thedivisor#If you want to give a prop a default value to use if no value is set, you can do it with destructuring by adding = followed by the default value right after the parameter:#thedivisor#Now, if <Avatar person={...} /> is shown without a size prop, the size will be set to 100.#thedivisor#The default value is used only if the size prop is not provided or if you pass size={undefined}. But if you pass size={null} or size={0}, the default value will not be used.