ampproject / amp-react-prototype

A scratch pad to experiment with React rendered AMP Components
Apache License 2.0
36 stars 9 forks source link

Property change states #47

Open dvoytenko opened 4 years ago

dvoytenko commented 4 years ago

Use case: <amp-carousel current-slide={value}>. The currentSlide is currently a "state" value and this is preferable. We could consider making it a controlled property coupled with onSlideChange callback, but that'd expand the API surface for something very simple. However, what should happen if the currentSlide prop (or "current-slide" attribute in DOM) has been updated? The simplified useStateFromProp hook supports updating the internal state when a prop changes, but it's not without issues. For instance, assuming the default prop/attribute value of currentSlide = 0, if the currentSlide state has been updated and the script simply wants to reset it back to the first slide, setting the currentSlide back to 0 will not work since technically the property's value will not change.