1. Create new app
npx create-react-app myapp
2. Edit workspace settings in vscode for flow typechecking
{
"flow.useNPMPackagedFlow": true,
"javascript.validate.enable": false
<FeatureTypeStyle> | |
<Rule> | |
<PointSymbolizer> | |
<Graphic> | |
<Mark> | |
<WellKnownName>circle</WellKnownName> | |
<Fill> | |
<CssParameter name="fill">#FF0000</CssParameter> | |
</Fill> | |
</Mark> |
<?xml version="1.0" encoding="utf-8"?> | |
<configuration> | |
<system.web> | |
<httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/> | |
</system.web> | |
<system.webServer> | |
<security> | |
<requestFiltering> | |
<requestLimits maxQueryString="32768"/> | |
</requestFiltering> |
1. Create new app
npx create-react-app myapp
2. Edit workspace settings in vscode for flow typechecking
{
"flow.useNPMPackagedFlow": true,
"javascript.validate.enable": false
yarn add -D enzyme enzyme-react-adapter-react-16
Create a file src/setupTests.js
. It will automatically get picked up by create-react-app.
In this file, put code to run before Tests. for example, to configure enzyme, put this in:
=== install deps === | |
sudo apt update | |
sudo apt install zsh fonts-powerline wget git | |
=== change default shell === | |
chsh -s /bin/zsh | |
=== (optional) verify installation === | |
which zsh -> 'usr/bin/zsh' | |
echo $SHELL -> 'usr/bin/zsh' |
const App = () => { | |
const [counter, setCounter] = useState(0); | |
const [aboveFive, setAboveFive] = useState(false); | |
const increment = () => { | |
setCounter(n => n + 1); | |
}; | |
useEffect(() => { | |
if (counter > 5) { |
shouldComponentUpdate(prevProps) { | |
return prevProps.isAboveFive !== this.props.isAboveFive; | |
} |
const Child = React.memo(({ isAboveFive, children }) => { | |
console.log("child renders"); | |
return ( | |
<> | |
<h2>Child: {!isAboveFive ? "<= 5" : "> 5"}</h2> | |
{children} | |
</> | |
); | |
}); |
const App = () => { | |
const [counter, setCounter] = useState(0); | |
const [aboveFive, setAboveFive] = useState(false); | |
const increment = () => { | |
setCounter(n => n + 1); | |
}; | |
useEffect(() => { | |
if (counter > 5) { |
const App = () => { | |
const [counter, setCounter] = useState(0); | |
const [aboveFive, setAboveFive] = useState(false); | |
const increment = () => { | |
setCounter(n => n + 1); | |
}; | |
useEffect(() => { | |
if (counter > 5) { |