
react-component-writing
by jakewaldrip
Dotfile configuration for my environment
SKILL.md
name: react-component-writing description: React component style guide
React components
Guidelines
- Export a named variable
export const ExampleComponent. Avoid default exports. - Avoid spread props
{...props}in GraphQL wrapper components. List all the props individually to improve type safety and linting. - Format the component function as a plain arrow function. Do not type with
React.FC.
UI components
For components that do not use GraphQL queries, writing UI components is straightforward. See example example-ui-component.tsx.
GraphQL components
For components that use GraphQL queries, component structure is separated into two components: the UI sub-component ExampleComponentUI and the GraphQL wrapper component, ExampleComponent. See example example-graphql-component.tsx.
Jest tests with GraphQL components
Jest tests for GraphQL components can be written in two ways:
- Test the UI sub-component, set props directly. See example-graphql-component-ui.spec.tsx
- Add GraphQL mocks. See example-graphql-component-mocks.spec.tsx
Internationalization
Most components use MessageFormat type to render internationalization text.
To render MessageFormat to a string, use useFormatMessage from Commonplace, as it is properly typed for MessageFormat. Do not use useIntl from react-intl.
import { Text, useFormatMessage } from '$commons/app/shared/commonplace';
const Component = ({ pageNumber }: { pageNumber: number }) => {
const formatMessage = useFormatMessage();
const nextText = formatMessage({ id: 'shared.next' });
return <Text text={`${nextText}: ${pageNumber}`} />;
};
Score
Total Score
Based on repository quality metrics
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
Reviews
Reviews coming soon