How to Deploy React App to S3 and CloudFront

If you would like to deploy a React App to AWS S3 and AWS CloudFront, then you can follow this guide. The following solution creates a React App and deploys it to S3 and CloudFront using the client’s CLI. It also chains commands so that a React build, S3 sync and CloudFront invalidation can occur with a single command. Code available at GitHub https://github.com/ao/deploy-react-to-s3-cloudfront Target Architecture Guided Deployment Solution Create a directory for the application:...

August 22, 2022 · 9 min · 1884 words · Andrew

[Solved] export ‘Switch’ (imported as ‘Switch’) was not found in ‘react-router-dom’

In react-router-dom v6, Switch is replaced by routes Routes. You need to update the import from: import { Switch, Route } from "react-router-dom"; to: import { Routes, Route } from 'react-router-dom'; You also need to update the Route declaration from: <Route path="/" component={Home} /> to: <Route path='/welcome' element={<Home/>} />

August 21, 2022 · 1 min · 49 words · Andrew

How to declare a global variable in React?

If you need to declare a global variable in React, then you can do the following: Create a file called config.js module.exports = global.config = { something: { somethingelse: { amount: 123, name: "Andrew" } } }; Then import the config file where you need it: import './config'; Then where you need it in your code: global.config.something.somethingelse.amount or global.config.something.somethingelse.name

May 4, 2022 · 1 min · 59 words · Andrew

How to Increment/Decrement a value in React/NextJS

Use the following code block to get started: function GetCount() { const [count, setCount] = useState(1); const incrementCounter = () => { setCount(count+1) } const decrementCounter = () => { if (count>1) setCount(count-1) } return <div className="_counterWrapper"> <span className="_dec" onClick={() => decrementCounter()}>-</span> <span className="_val">{count}</span> <span className="_inc" onClick={() => incrementCounter()}>+</span> </div> } Then in your HTML code, add it like this: <GetCount />

May 1, 2022 · 1 min · 62 words · Andrew