
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
generate-react-code
Advanced tools
An automated React code generation tool for React web, React-Native, and/or Redux in the ducks modular pattern.
This project utilises a scaffolding framework which generates React or React-Native code along with all the essential test code... Because who likes writing that themselves?!
Additionally, it can be used to generate Redux code conforming to the Redux ducks pattern - and it can also be used to
generate the Redux core files needed for React-Redux projects (store
, root-reducer
, and action-utilities
).
This generated code conforms to the Air BnB style guide's naming and coding-style conventions, and it is thus highly recommended to make use of this tool when creating new React or React-Redux components.
This package also allows users to add a configuration file containing default parameters. That way users would not have to specify these parameters every time they wish to generate code.
IMPORTANT NOTE:
To install and save this npm package, navigate to your project's root directory in console and execute the following command:
npm install generate-react-code --save-dev
Then add the following script to your packages.json
file:
{
"scripts": {
"gen-react-code": "generate-react-code"
}
}
The following command can be used to generate code:
npm run gen-react-code -- -n example-component -d src/example/dir -r
Parameter | Description | Default Value |
---|---|---|
-n OR--name | This is the lower kebab case name of the feature/component you would like to generate (e.g. kebab-example-name ). | kebab-example-name |
-d OR--directory | This is the relative directory where the generated component will be placed (e.g src/components ). | src/components |
-N OR--native | If you wish to generate code for React-Native, add this parameter - else React web code will be generated. | false |
-r OR--redux | If you wish to generate Redux code in the duck pattern, add this parameter - else regular React code will be generated. | false |
-o OR--omit-comments | If you wish to hide the comments within the generated files, add this parameter - else descriptive comments will be left in the generated code. | false |
-R OR--redux-core | If you would like to generate the Redux core files (store , root-reducer , and action-utilities ), add this parameter. These files are used to connect your application with Redux. | false |
-D OR--redux-core-directory | This is the relative directory where the generated Redux core file will be placed (e.g src/redux ). It is recommended to leave this as the default. | src/redux |
-h OR--help | Output help usage information. |
If you wish to store default parameters for your project, you'll have to add an optional grcc.json
(generate react code config) file to your project's root directory.
The file must have the following structure:
{
"native": true,
"redux": true,
"omitComments": true
}
IMPORTANT NOTE:
false
by default. The parameters you wish to remain so, may be omitted from the file.grcc.json
file.grcc.json
file is completely optional and does not have to be added.Given the following example code generation command:
npm run gen-react-code -- -n example-component -d src/components
The following file/folder structure will be generated (take note that the example-component
directory is generated without you having to specify it explicitly):
project
└───src
└───components
└───example-component
│ example-component.view.js
│ _example-component.styles.scss
└───test
│ example-component.view.spec.js
Within these files the majority of the React code will be completed for you - which contains detailed comments on how to add your functionality and general best practices.
IMPORTANT NOTE:
src/index.scss
Given the following grcc.json
config file:
{
"native": true,
"redux": true
}
And given the following example code generation command:
npm run gen-react-code -- -n example-component -d src/components
The following file/folder structure will be generated (take note that the example-component
directory is generated without you having to specify it explicitly):
project
└───src
└───components
└───example-component
│ example-component.view.js
│ _example-component.styles.scss
└───test
│ example-component.view.spec.js
Within these files the majority of the React code will be completed for you - which contains detailed comments on how to add your functionality and general best practices.
IMPORTANT NOTE:
src/index.scss
Given the following example code generation command:
npm run gen-react-code -- -n example-component -d src/components -N
The following file/folder structure will be generated (take note that the example-component
directory is generated without you having to specify it explicitly):
project
└───src
└───components
└───example-component
│ example-component.view.js
└───test
│ example-component.view.spec.js
Within these files the majority of the React-Native code will be completed for you - which contains detailed comments on how to add your functionality and general best practices.
Given the following example code generation command:
npm run gen-react-code -- -n example-component -d src/components -r
The following file/folder structure will be generated (take note that the example-component
directory is generated without you having to specify it explicitly):
project
└───src
└───components
└───example-component
│ example-component.container.js
│ example-component.reducer.js
│ example-component.view.js
│ _example-component.styles.scss
└───test
│ example-component.container.spec.js
│ example-component.reducer.spec.js
│ example-component.view.spec.js
Within these files the majority of the React web code will be completed for you - which contains detailed comments on how to add your functionality and general best practices.
IMPORTANT NOTE:
src/redux/root-reducer.js
src/index.scss
Given the following example code generation command:
npm run gen-react-code -- -R
The following file/folder structure will be generated (take note that adding the -R
parameter will cause only the
core files to be generated, irrespective of the other parameters):
project
└───src
└───redux
│ store.js
│ root-reducer.js
└───action-creator
│ build-action-type.js
│ create-action.js
└───test
│ build-action-type.spec.js
│ create-action.spec.js
Within these files the majority of the React-Redux core code will be completed for you - which contains detailed comments on how to add your reducers and general best practices.
IMPORTANT NOTE:
store
to your Redux Provider
where you're rendering your main app, which is usually located in src/index.js
A great example on how to use generate-react-code
can be found here (courtesy of ZuluCoda).
FAQs
An automated React code generation tool for React web, React-Native, and/or Redux in the ducks modular pattern.
We found that generate-react-code demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.