Components
React components include common best practices for good performances, maintainability and ease of use. Here are some of the design decisions for the generated code.
Last updated
Was this helpful?
React components include common best practices for good performances, maintainability and ease of use. Here are some of the design decisions for the generated code.
Last updated
Was this helpful?
.
Clapy components are written using functions. Most modern React code is written using functions and hooks. It can remain simple and most libraries will provide their features as rather or other class-specific implementations.
We consider components should be memoized by default, which should be beneficial in most cases. If it appears to have a negative impact on specific scenarios, the impact remains very small and memoization can be removed in that case.
Find out more here:
For this reason, all generated components are wrapped into memo()
.
All properties exposed by the component for overrides are listed in the component Props
â interface. Please refer to the for more details about the overrides.
All components use named exports. While many examples on Internet use default exports, named exports have more benefits, e.g. in terms of usage (auto-import, auto-completion from IDEs) and performance (considering ES6 modules and tree shaking).
Card
is defined twice: as the exported variable name and the inner function.
The exported variable is required for named exports.
The inner function is named (instead of anonymous) to name the component function, which helps showing better stack traces when debugging. This practice can be enforced by an ESLint config.
In TypeScript, imports of other TypeScript files typically don't have extensions. E.g.:
To be able to bundle in ES module format and be compatible with the latest standards and usages around ES modules, the recommendation is to append a ".js" extension to imports (yes, even if pointing to a TypeScript file). E.g.:
That's the practice Clapy has adopted in the generated code.
This annotation is added in a comment above the component. Please leave it as it is. In an incoming release, we will use it to map a coded component to the corresponding Figma node, e.g. for updates.
It's an assumption TypeScript has made in its early days, but not the final standard of EcmaScript modules. (at least for me), the TypeScript transpilation to JavaScript doesn't add the .js extension.