This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
const audioDataCount = await axios.post(netlifyConfig().DOMAIN + 'get-scene-audio-count', { | |
email: value.email, | |
sourceID: value.sourceID, | |
source: value.source | |
}) | |
console.log('audioDataCount', audioDataCount) | |
const res = { | |
count: audioDataCount.data.audioScenesList.count, | |
data: audioDataCount.data.audioScenesList.items |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ApexLegendsGameResult = { | |
teamID: string, | |
placement: number, | |
kills: number | |
}; | |
application.post('/apex-legends/:gameID/report-score', async ({params: {gameID}, body}, res) => { | |
await db.collection('apexLegendsGames').updateOne({ | |
_id: gameID | |
}, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ApexLegendsGameResult = { | |
teamID: string, | |
placement: number, | |
kills: number | |
}; | |
application.post('/apex-legends/:gameID/report-score', async ({params: {gameID}, body}, res) => { | |
const results: ApexLegendsGameResult[] = body; | |
await db.collection('apexLegendsGames').updateOne({ | |
_id: gameID | |
}, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ApexLegendsGameResult = { | |
teamID: string, | |
placement: number, | |
kills: number | |
}; | |
application.post('/apex-legends/:gameID/report-score', async ({params: {gameID}, body}, res) => { | |
await db.collection('apexLegendsGames').updateOne({ | |
_id: gameID | |
}, { | |
$set: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BEFORE | |
const [state, setState] = useState(); | |
useEffect(() => { | |
setState(calculateInitialState()); | |
}, []); | |
// AFTER | |
const [state, setState] = useState(calculateInitialState); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BEFORE | |
const [costlyValue, setCostlyValue] = setState(); | |
useEffect(() => { | |
setCostlyValue(computedCostlyValue(props.someParam)); | |
}, [props.someParam]); | |
// AFTER | |
const costlyValue = useMemo(() => computedCostlyValue(props.someParam), [props.someParam]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BrokenComponent = (props) => { | |
useEffect(() => { | |
console.log('BrokenComponent called useEffect'); | |
}, [props]); // THIS IS ALWAYS WRONG! | |
return <code>{JSON.stringify(props)}</code>; | |
}; | |
const GoodComponent = (props) => { | |
useEffect(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Good useMemo usage | |
const NormalComponent = ({ count }) => { | |
const costlyValue = useMemo(() => costlyFunction(count), [count]); | |
return <p>NormalComponent {costlyValue}</p>; | |
}; | |
export default ({ count }) => { | |
// Slow component | |
const SlowComponent = () => { | |
const costlyValue = costlyFunction(count); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BEFORE | |
const App = () => { | |
const [locale, setLocale] = useState('english'); | |
return <Navigation locale={locale} />; | |
}; | |
const Navigation = ({ locale }) => { | |
return <Link locale={locale} href="/about">About</Link>; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BAD | |
export default ({ count }) => { | |
const Label = () => { | |
return <code>{count}</code>; | |
}; | |
return <Label />; | |
}; | |