#thedivisor#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">Clock</code> component below receives two props from its parent component: <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">color</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">time</code>. (The parent component’s code is omitted because it uses <a 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" href="/learn/state-a-components-memory">state</a>, which we won’t dive into just yet.)#thedivisor#Try changing the color in the select box below:#thedivisor#This example illustrates that <strong class="font-bold">a component may receive different props over time.</strong> Props are not always static! Here, 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">time</code> prop changes every second, and 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">color</code> prop changes when you select another color. Props reflect a component’s data at any point in time, rather than only in the beginning.#thedivisor#However, props are <a href="https://en.wikipedia.org/wiki/Immutable_object" 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">immutable</a>—a term from computer science meaning “unchangeable”. When a component needs to change its props (for example, in response to a user interaction or new data), it will have to “ask” its parent component to pass it <em>different props</em>—a new object! Its old props will then be cast aside, and eventually the JavaScript engine will reclaim the memory taken by them.#thedivisor#<strong class="font-bold">Don’t try to “change props”.</strong> When you need to respond to the user input (like changing the selected color), you will need to “set state”, which you can learn about in <a 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" href="/learn/state-a-components-memory">State: A Component’s Memory.</a>#thedivisor#<li class="leading-relaxed mb-1">To pass props, add them to the JSX, just like you would with HTML attributes.</li>
#thedivisor#The Clock component below gets two props from its parent component: color and time. (The parent component’s code is not shown because it uses state, which we will not discuss right now.)#thedivisor#Try changing the color in the select box below:#thedivisor#This example shows that a component can receive different props over time. Props are not always the same! Here, the time prop changes every second, and the color prop changes when you select a different color. Props show a component’s data at any time, not just at the start.#thedivisor#However, props are immutable—this means “unchangeable.” When a component needs to change its props (for example, when responding to user input or new data), it has to “ask” its parent component for different props—a new object! The old props will then be ignored, and eventually, the JavaScript engine will free the memory used by them.#thedivisor#Don’t try to “change props”. When you need to respond to user input (like changing the selected color), you will need to “set state,” which you can learn about in State: A Component’s Memory.#thedivisor#To pass props, add them to the JSX just like you would with HTML attributes.