DEV Community

Discussion on: Explain State and Props Like I'm Five

Collapse
 
vonheikemen profile image
Heiker • Edited

Maybe not quite accurate, but here I go:

Think in a sandwich. You can imaging two types of ingredients, there are the ones that you put in like tomato, bacon or cheese. This come from the outside world. But the bread itself is also made of some ingredients, those are already baked in. You could make a sandwich component like this:

<my-sandwich vegetable="tomato" />

See. In here you pass a vegetable of your choice to the sandwich component. You can think of state as values that live inside the component. And props as values that come from the outside.

I also like to think of components as functions (in some libraries that is actually the case), and in that sense the "props" are just the arguments that you give to the component and state are the variables that you declare inside the component.