Quick Start
- Run:
npm i
- Run:
npm start
- Open the localhost port 3000 on your web browser.
Code Scaffolding
You can use a generate
command to create component or container with given template.
Container
- Run:
npm run generate container
- Put name of the new container
- Put any color for the dummy background. This will help for layouting.
- Go to the
/app/container
folder - Make some adjustment
Component
- Run:
npm run generate component
- Put name of the new component
- Go to the
/app/component
folder - Make some adjustment
State Management
We use React Context API and React useReducer helper to maintain a global state.
Setting State
To set a global state, we do as follow:
import { useCurrentData } from 'hooks';
function MakePayment() {
const currentData = useCurrentData();
const [amountToPay, setAmountToPay] = useState(500);
const setGlobalDataFromState = () => {
currentData.set({ amountToPay: amountToPay })
};
// ...
Getting State
To get a global state, we do as follow:
import { useCurrentData } from 'hooks';
function MakePayment() {
const currentData = useCurrentData();
const [amountToPay, setAmountToPay] = useState();
const setLocalStateFromGlobalState = () => {
// Note that param must match the key on the setter
const prevAmountToPay = currentData.get('amountToPay');
setAmountToPay(prevAmountToPay);
};
// ...