Skip to content

Instantly share code, notes, and snippets.

@FaiChou
Created February 23, 2022 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FaiChou/cbbf5854d9b3efebe92ecb6cc3820000 to your computer and use it in GitHub Desktop.
Save FaiChou/cbbf5854d9b3efebe92ecb6cc3820000 to your computer and use it in GitHub Desktop.
function Detail() {
const [x, addOneToX] = React.useReducer(x=>x+1,0);
const [, forceUpdate] = React.useReducer(x=>x+1,0);
console.log('render: ', x);
React.useEffect(() => {
console.log('effect: ', x);
return function() {
console.log('cleanup: ', x);
}
}, [x]);
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Detail!</Text>
<Button title="x" onPress={addOneToX} />
<Button title="forceupdate" onPress={forceUpdate} />
</View>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment