yoshuawuyts / microcomponent

Smol event based component library
MIT License
35 stars 11 forks source link

Question: State vs props #25

Closed mfolkeseth closed 5 years ago

mfolkeseth commented 7 years ago

Hi,

I am curious to what the distinction is between state and props and when to use them. Am I assuming correctly that props are for external use and state for internal?

I think that the example in Readme needs to be updated as the props from microcomponent constructor returns undefined in the render function (they are oldProps). I might be totally off here, just thinking out loud 🙃

juliangruber commented 7 years ago

props are what you call your component with:

${component.render(thoseAreProps)}

State is the component's internal state. You could also just attach state yourself, but it's cleaner to use the already provided object.

mfolkeseth commented 7 years ago

Thanks for the clearification. As i mentioned, the example in reader needs to be updated, either pass text in the render method or change props to state in the micro component constructor.