Use command line to create component or something else
npm install create-react-file -g
$ create-react-file Component
Create folder ./Component
and file Component.jsx
, index.js
, Component.css
.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
class Component extends Component {
constructor(props) {
super(props);
}
static propTypes = {};
static defaultProps = {};
state = {};
render() {
const { className, children, ...others } = this.props;
const cls = classnames({
'components-component-render': true,
[className]: !!className,
});
return (
<div className={cls} {...others}>
{ children }
</div>
);
}
}
export default Component;
.components-component-render {
}
import './Component.scss';
import Component from './Component';
export default Component;
$ create-react-file --help
Usage: create-react-file [options] <name> [parentName]
Options:
-f, --function create function component
-p, --page create component as page
-s, --single create single file Component.jsx
-h, --hooks create file hooks.js
-h, --help output usage information
Little tip with oh my zsh.
Changing .zshrc
like this makes the tool be more convenient.
alias cf="create-react-file"
alias cfp="create-react-file -p"