react-component

Crates.ioreact-component
lib.rsreact-component
version0.2.6
sourcesrc
created_at2023-02-02 23:18:53.889349
updated_at2023-03-03 23:13:44.618003
descriptionA CLI tool to generate React component files
homepage
repositoryhttps://github.com/wbroberts/react-component
max_upload_size
id775233
size20,667
William Roberts (wbroberts)

documentation

README

React Component

I wanted to learn Rust and wanted to compare it to Go. So I made a simple CLI tool to generate some boilerplate react component files.

Installation

cargo install react-component

How To Use

react-component --help
react-component <component name> <...options>

Example

react-component Example --path src/components/examples

Generates three files:

  • src/components/examples/Example.component.tsx
import React from 'react';

export type ExampleProps = {};

export const Example: React.ComponentType<ExampleProps> = ({}) => {
  return (<div>Example renders</div>);
};
  • src/components/examples/Example.test.tsx
import { screen, render } from '@testing-library/react';

import { Example } from './Example.component';

describe('Example', () => {
  it('renders', () => {
    render(<Example />);
    expect(screen.getByText(/Example renders/)).toBeDefined();
  });
});
  • src/components/examples/Example.stories.tsx
import { ComponentMeta, Story } from '@storybook/react';

import { Example, ExampleProps } from './Example.component';

const story: ComponentMeta<typeof Example> = {
  title: 'Example'
};

export const ExampleStory: Story<ExampleProps> = (args) => {
  return (<Example {...args} />)
};

export default story;
Commit count: 13

cargo fmt