Author: Wang Ergou blog: personal blog, nuggets, Zhihu praise again, form a habit, your support is the biggest power I continue to share 😘
Recently, I have been busy with the business of small program. At present, I plan to split the whole small program into different components, and finally build the whole small program using components.
So in the process of developing components, I have some thoughts on how to write components, and share them with you, hoping to inspire you.
Encapsulation openness
When encapsulating a component, the first thing you need to think about is which properties of the component you want to encapsulate internally, and which properties you want to expose to the users of the component to call.
If all properties are encapsulated within a component, it is obvious that the component is very inflexible and can be applied in very few scenarios.
If a component has too many open attributes, it will inevitably become “cumbersome” and not maintainable.
If your component really needs to expose a lot of properties, you can think about it in terms of component granularity, which we’ll talk about next.
Component granularity
A component can encapsulate a very simple function or a very complex function.
When you write a component, you should think about what features should and should not be wrapped into my component.
There is no absolute answer, and it depends on your own business and the environment of your current team.
Small components have the benefits of small components, which are very flexible.
Large components also have the benefits of large components, large components we use, very convenient.
Tell yourself that even if you are tired, don’t forget to learn. There is no shortcut to success, only step by step. ‘!
If there is something wrong in the article, you are welcome to correct it.
Thank you ~ 💘