DEV Community

Give names to behaviors not interactions

Sid on January 03, 2019

When it comes to React components, props are the API that developers consume. A good API should be obvious, something the developer can guess. You ...
Collapse
 
dance2die profile image
Sung M. Kim

Thank you, Sid. It was very helpful 👋.

How I understood was that, one should specify "what" (declarative) a component should do not "how" (imperative) it should do.

So in the Switch example, onClick specifies "how" a user should interact with it, while onChange exposes a general behavior of "what" the component can do.

Would you correct my understanding as I could be getting the whole abstraction wrong 😅

Collapse
 
siddharthkp profile image
Sid

That's the perfect way of looking at it!

Collapse
 
dance2die profile image
Sung M. Kim

😄👊

Collapse
 
enieber profile image
Enieber Cunha

Very good your post. How do you see use this pattern to react-native?

Collapse
 
siddharthkp profile image
Sid

I don't use react-native but I'd say the ideas still make sense .The implementation details might change, but the API would look the same