š ļø Automate Your React Native Workflow with a Custom Yarn Command
Create React Native components with a single command and boost your dev productivity š
š ļø Automate Your React Native Workflow with a Custom YarnĀ Command
Create React Native components with a single command and boost your dev productivity š
š„ Read for free š

š¤ TheĀ Problem
As a React Native developer, one of the most repetitive tasks we all face is setting up component folders:
index.tsxfor the UIstyles.tsfor stylesuseComponent.tsfor custom logic
You know the drill. Every time, we write the same boilerplateāāāwasting time and breaking focus.
Wouldnāt it be amazing to just run something like:

ā¦and instantly have this?

Letās make that dream real. š„
šÆ What YouāllĀ Build
A simple, reusable CLI tool using a Yarn script that:
- Takes a component name (
Header,LoginForm, etc.) - Creates a folder under
/components/ - Adds
index.tsx,styles.ts, anduseComponent.tsfiles - Uses standard React Native + TypeScript boilerplate
All this with just one command.
āļø Step 1: Create theĀ Script
At the root of your project, create a folderāāāscripts
and create a typescript file
touch generate-component.jsNow paste this code:
const fs = require('fs');
const path = require('path');
const componentName = process.argv[2];
if (!componentName) {
console.error(
'ā Please provide a component name (e.g. yarn component [Component Name]])',
);
process.exit(1);
}
const basePath = path.join(
`${__dirname}`,
'..',
'src',
'components',
componentName,
);
if (fs.existsSync(basePath)) {
console.error(`ā ${componentName} Component already exists!`);
process.exit(1);
}
fs.mkdirSync(basePath, { recursive: true });
// index.tsx
fs.writeFileSync(
path.join(basePath, 'index.tsx'),
`import React from 'react';
import { View, Text } from 'react-native';
import styles from './styles';
import use${componentName} from './use${componentName}';
const ${componentName} = () => {
const {} = use${componentName}();
return (
<View style={styles.container}>
<Text>${componentName} Component</Text>
</View>
);
};
export default ${componentName};
`,
);
// styles.ts
fs.writeFileSync(
path.join(basePath, 'styles.ts'),
`import { StyleSheet } from 'react-native';
export default StyleSheet.create({
container: {
padding: 16,
},
});
`,
);
// useComponent.ts
fs.writeFileSync(
path.join(basePath, `use${componentName}.ts`),
`const use${componentName} = () => {
return {};
};
export default use${componentName};`,
);
console.log(
`ā
Component ${componentName} created in components ${componentName}`,
);š§© Step 2: Add a YarnĀ Script
Open your package.json and add this under scripts:
"scripts": {
"component": "node scripts/generate-component.ts"
}This lets you run yarn component ComponentName, where component is a custom alias for the component generator.
š§Ŗ Step 3: UseĀ It!
yarn component HeadersBoom š„!
Your src/components/Header/ folder will be created with all the essential files.
š” Why This IsĀ Awesome
- š§ Saves mental energy
- ā±ļø Boosts speed
- š§¹ Keeps folder structure consistent
- š§° Easy to extend for screens, Redux modules, tests, etc.
This is the kind of small productivity booster that pays off big over time.
Instead of creating folders manually 100+ times across a project, automate it once and focus your energy on building actual features.
Let me know in the comments if you want a create-screen version with navigation next. š¬
š Follow Me forĀ More
Did you find this helpful? Give a Clap and Share it with your friends!
For more updates: subscribe to my medium account.
Thank you for reading š