├── .env ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.js ├── App.test.js ├── assets │ └── sass │ │ ├── _global.scss │ │ ├── _layout.scss │ │ ├── _variable.scss │ │ └── component │ │ └── index.scss ├── component │ ├── atoms │ │ └── index.js │ ├── molecules │ │ └── index.js │ └── organisms │ │ └── index.js ├── helper │ └── http.js ├── index.js ├── index.scss ├── pages │ ├── Home.js │ └── Profile.js ├── redux │ ├── actions │ │ └── authActions.js │ ├── reducers │ │ ├── authReducer.js │ │ └── index.js │ └── store.js ├── routes │ ├── index.js │ └── web.js ├── serviceWorker.js └── setupTests.js └── yarn.lock /.env: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # React Js Boilerplate 3 | 4 | ![](https://img.shields.io/github/stars/kubil-ismail/react-js-boilerplate) 5 | ![](https://img.shields.io/github/forks/kubil-ismail/react-js-boilerplate) 6 | ![](https://img.shields.io/github/tag/kubil-ismail/react-js-boilerplate) 7 | ![](https://img.shields.io/github/release/kubil-ismail/react-js-boilerplate) 8 | ![](https://img.shields.io/github/issues/kubil-ismail/react-js-boilerplate) 9 | 10 | # About 11 | React Js Boilerplate is a React js template to create web and make the development process even faster. 12 | 13 | ## Installation 14 | 15 | Clone this repo 16 | 17 | ```bash 18 | https://github.com/kubil-ismail/react-js-boilerplate.git 19 | ``` 20 | Intall dependency. 21 | 22 | ```bash 23 | cd react-js-boilerplate 24 | npm install 25 | npm start 26 | ``` 27 | 28 | ## Package 29 | 30 | - **[axios](https://www.npmjs.com/package/axios)** 31 | - **[bootstrap](https://www.npmjs.com/package/bootstrap)** 32 | - **[node-sass](https://www.npmjs.com/package/node-sass)** 33 | - **[react-bootstrap](https://www.npmjs.com/package/react-bootstrap)** 34 | - **[react-redux](https://www.npmjs.com/package/react-redux)** 35 | - **[react-router-dom](https://www.npmjs.com/package/react-router-dom)** 36 | - **[redux](https://www.npmjs.com/package/redux)** 37 | - **[redux-persist](https://www.npmjs.com/package/redux-persist)** 38 | - **[redux-promise-middleware](https://www.npmjs.com/package/redux-promise-middleware)** 39 | 40 | ## Contributing 41 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 42 | 43 | Please make sure to update tests as appropriate. 44 | 45 | ## License 46 | [MIT](https://choosealicense.com/licenses/mit/) 47 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-js-boilerplate", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.3.2", 8 | "@testing-library/user-event": "^7.1.2", 9 | "axios": "^0.19.2", 10 | "bootstrap": "^4.5.0", 11 | "node-sass": "^4.14.1", 12 | "react": "^16.13.1", 13 | "react-bootstrap": "^1.3.0", 14 | "react-dom": "^16.13.1", 15 | "react-redux": "^7.2.1", 16 | "react-router-dom": "^5.2.0", 17 | "react-scripts": "3.4.1", 18 | "redux": "^4.0.5", 19 | "redux-persist": "^6.0.0", 20 | "redux-promise-middleware": "^6.1.2" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": "react-app" 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | }, 43 | "devDependencies": { 44 | "redux-logger": "^3.0.6" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubil-ismail/react-js-boilerplate/341deb6dfde23a308ae60b92a00e42e9b07696f0/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubil-ismail/react-js-boilerplate/341deb6dfde23a308ae60b92a00e42e9b07696f0/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubil-ismail/react-js-boilerplate/341deb6dfde23a308ae60b92a00e42e9b07696f0/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Routes from './routes'; 3 | 4 | // Use Redux 5 | import { Provider } from 'react-redux'; 6 | import { PersistGate } from 'redux-persist/integration/react'; // Imports: Redux Persist Persister 7 | import { store, persistor } from './redux/store'; // Import redux store 8 | 9 | export default class App extends Component { 10 | render() { 11 | return ( 12 | 13 | 14 | 15 | 16 | 17 | ); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/assets/sass/_global.scss: -------------------------------------------------------------------------------- 1 | /* make the customizations */ 2 | // $theme-colors: ( 3 | // "info": tomato, 4 | // "danger": teal 5 | // ); 6 | 7 | @import "~bootstrap/scss/bootstrap"; -------------------------------------------------------------------------------- /src/assets/sass/_layout.scss: -------------------------------------------------------------------------------- 1 | @import './variable'; 2 | @import './global'; 3 | @import './component/index.scss'; -------------------------------------------------------------------------------- /src/assets/sass/_variable.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubil-ismail/react-js-boilerplate/341deb6dfde23a308ae60b92a00e42e9b07696f0/src/assets/sass/_variable.scss -------------------------------------------------------------------------------- /src/assets/sass/component/index.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubil-ismail/react-js-boilerplate/341deb6dfde23a308ae60b92a00e42e9b07696f0/src/assets/sass/component/index.scss -------------------------------------------------------------------------------- /src/component/atoms/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubil-ismail/react-js-boilerplate/341deb6dfde23a308ae60b92a00e42e9b07696f0/src/component/atoms/index.js -------------------------------------------------------------------------------- /src/component/molecules/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubil-ismail/react-js-boilerplate/341deb6dfde23a308ae60b92a00e42e9b07696f0/src/component/molecules/index.js -------------------------------------------------------------------------------- /src/component/organisms/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubil-ismail/react-js-boilerplate/341deb6dfde23a308ae60b92a00e42e9b07696f0/src/component/organisms/index.js -------------------------------------------------------------------------------- /src/helper/http.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | const URL = process.env.REACT_APP_REST; 3 | 4 | // Fetch Data 5 | export const get = async (data) => { 6 | try { 7 | const response = await axios.get(`${URL + data.url}`, data.body, data.config); 8 | return response; 9 | } catch (error) { 10 | return error; 11 | } 12 | }; 13 | 14 | // Post Data 15 | export const post = async (data) => { 16 | try { 17 | const response = await axios.post(`${URL + data.url}`, data.body, data.config); 18 | return response; 19 | } catch (error) { 20 | return error; 21 | } 22 | }; 23 | 24 | // Patch Data 25 | export const patch = async (data) => { 26 | try { 27 | const response = await axios.patch(`${URL + data.url}`, data.body, data.config); 28 | return response; 29 | } catch (error) { 30 | return error; 31 | } 32 | }; 33 | 34 | // Delete Data 35 | export const remove = async (data) => { 36 | try { 37 | const response = await axios.delete(`${URL + data.url}`, data.body, data.config); 38 | return response; 39 | } catch (error) { 40 | return error; 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | import * as serviceWorker from './serviceWorker'; 5 | 6 | // Import style 7 | import './index.scss'; 8 | 9 | ReactDOM.render( 10 | 11 | 12 | , 13 | document.getElementById('root') 14 | ); 15 | 16 | // If you want your app to work offline and load faster, you can change 17 | // unregister() to register() below. Note this comes with some pitfalls. 18 | // Learn more about service workers: https://bit.ly/CRA-PWA 19 | serviceWorker.unregister(); 20 | -------------------------------------------------------------------------------- /src/index.scss: -------------------------------------------------------------------------------- 1 | // Import main style 2 | @import './assets/sass/layout'; -------------------------------------------------------------------------------- /src/pages/Home.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | export default class Home extends Component { 4 | render() { 5 | return ( 6 | <> 7 |

Home App

8 | 9 | ); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/pages/Profile.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | // Use Redux 4 | import { connect } from 'react-redux'; 5 | import { login } from '../redux/actions/authActions'; 6 | 7 | export class Profile extends Component { 8 | componentDidMount = () => { 9 | this.props.login(); 10 | } 11 | 12 | render() { 13 | return ( 14 | <> 15 |

Profile App

16 | 17 | ); 18 | } 19 | } 20 | 21 | const mapStateToProps = (state) => ({ 22 | auth: state.auth, 23 | }); 24 | 25 | const mapDispatchToProps = { login }; 26 | 27 | export default connect(mapStateToProps, mapDispatchToProps)(Profile); 28 | -------------------------------------------------------------------------------- /src/redux/actions/authActions.js: -------------------------------------------------------------------------------- 1 | export const login = (request = null) => { 2 | return { 3 | type: 'LOGIN', 4 | payload: request, 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/redux/reducers/authReducer.js: -------------------------------------------------------------------------------- 1 | const defaultState = { 2 | loading: false, 3 | result: [], 4 | options: [], 5 | }; 6 | 7 | const reducer = (state = defaultState, action) => { 8 | switch (action.type) { 9 | // Login Promise 10 | case 'LOGIN': { 11 | return { 12 | ...defaultState, 13 | loading: true 14 | }; 15 | } 16 | case 'LOGIN_FULFILLED': { 17 | return { 18 | ...defaultState, 19 | loading: false 20 | }; 21 | } 22 | // DEFAULT 23 | default: { 24 | return state; 25 | } 26 | } 27 | }; 28 | 29 | export default reducer; -------------------------------------------------------------------------------- /src/redux/reducers/index.js: -------------------------------------------------------------------------------- 1 | import { combineReducers } from 'redux'; 2 | 3 | // Reducers 4 | import authReducer from './authReducer'; 5 | 6 | export default combineReducers({ 7 | auth: authReducer 8 | }); -------------------------------------------------------------------------------- /src/redux/store.js: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware } from 'redux'; // Redux 2 | import { persistStore, persistReducer } from 'redux-persist'; // Redux Persist 3 | import { createLogger } from 'redux-logger'; // Redux Logger 4 | import storage from 'redux-persist/lib/storage'; // Redux Persist Storage 5 | import promiseMiddleware from 'redux-promise-middleware'; // Promise Middleware 6 | import rootReducer from './reducers'; // Import Reducer 7 | 8 | // Middleware: Redux Persist Config 9 | const persistConfig = { 10 | // Root 11 | key: 'primary', 12 | // Storage Method 13 | storage: storage, 14 | // Whitelist (Save Specific Reducers) 15 | whitelist: ['auth'], 16 | // Blacklist (Don't Save Specific Reducers) 17 | blacklist: [], 18 | }; 19 | 20 | // Middleware: Redux Persist Persisted Reducer 21 | const persistedReducer = persistReducer(persistConfig, rootReducer); 22 | 23 | // Redux: Store 24 | const store = createStore( 25 | persistedReducer, 26 | applyMiddleware( 27 | promiseMiddleware, 28 | createLogger() // Remove in production mode 29 | ) 30 | ); 31 | 32 | // Middleware: Redux Persist Persister 33 | const persistor = persistStore(store); 34 | 35 | // Exports 36 | export { store, persistor }; 37 | -------------------------------------------------------------------------------- /src/routes/index.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'; 3 | 4 | // Import routes 5 | import { Home, Profile } from './web'; 6 | 7 | export default class Routes extends Component { 8 | render() { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | 16 | ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/routes/web.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | // Import page 4 | import HomePage from '../pages/Home'; 5 | import ProfilePage from '../pages/Profile'; 6 | 7 | // Export Page 8 | export const Home = () => { 9 | return ; 10 | }; 11 | 12 | export const Profile = () => { 13 | return ; 14 | }; 15 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' }, 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready 134 | .then(registration => { 135 | registration.unregister(); 136 | }) 137 | .catch(error => { 138 | console.error(error.message); 139 | }); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | --------------------------------------------------------------------------------