that uses react / typescript / scss / redux / react-router-dom / jest / react-testing-library / eslint / prettier.
- fork this repo
- clone the forked repo
- run
yarn
- run
yarn serve
yarn serve
to serve the app for developementyarn build
to build app for productionyarn test
to start jest testingyarn format
to format code in prettieryarn format:check
to check if code style matches onlyyarn format:write
to prettify your code onlyyarn lint
to lint your code in eslintyarn lint:fix
to fix code in eslintyarn test
to test code in jest
.
├── .github
| └── workflow
| └── ...
├── .vscode
| └── ...
├── src
| ├── components
| | └── ...
| ├── redux
| | ├── actions
| | ├── reducers
| | └── ...
| ├── styles
| | └── ...
| ├── utils
| | └── ...
| └── ...
├── tests
| ├── __snapshot
| └── ...
├── webpack
| └── ...
└── ...
this repo can also be usefull for test first driven testing method, it uses jest / react-testing-library / react-test-renderer. It also contain how to test redux. I have made custom util to create test store not redux mock store because it is only for testing action based logic not reducer. A simple test example
it("should render component properly",()=>{
// createTestStore is a utility in src/utils folder
const store=createTestStore();
// you can also spyOn store.dispatch
const spy = jest.spyOn(store,"dispatch");
render(
<MemoryRouter>
<Provider store={store}>
<Component></Component>
</Provider>
</MemoryRouter>,
);
const element =screen.fintByTestId("test_id");
expect(element).toHaveTextContent("first content");
act(()=>{
fireEvent.click(add);
})
expect(spy).toHaveCalled();
expect(element).toHaveTextContent("changed content after click");
});
this repo uses webpack to bundle scss , typescript and file. webpack folder contain three webpack configs, webpack.config.ts is main config which is merged in other config based on mode. There are two mode, developement and production. In developement mode hmr is in use and in production, minification of the code in done. this repo use ts-loader to load typescript, scss-loader / css-loader to load css and mini-css-extract-plugin creates a seperate css file. To use hmr, this repo use react-hot-replacer.
there is a github action in .github to continuosly check code quality. I have set of instruction like yarn lint
, yarn format
, yarn test
.
this repo is a react boilerplate and uses redux for statemanagement. If you dont know redux visit there doc; For routing it uses react router dom. If you are using react-router-dom and you project is growing , you can create a folder called pages in src where you can store all routes.
this repo recommend using vscode to get full advancement code linting and formating. With linting and formating , i have also made vscode tasks that you can run from your vscode. go to terminal > Run task > you will get list of tasks , run one of them.
why you should make react app from scratch if you have create-react-app. create-react-app itself says that is it for learning, it is not truely suitable for production. If you make react app from scratch, you will get good understanding of react and webpack. Making your own react app gives you power of configurations,this can be very usefull if you app grows. create-react-app is actually slow for some reasons. I spent lot of time collecting pieces of code that will actually work with my stack. Thats why I made a repo and put everything in this that i will use it for my future project and open sourced it to give other poeple its benefit.