-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Augustin Le Fèvre
committed
Jun 30, 2019
1 parent
cc1ac06
commit 0579f1d
Showing
12 changed files
with
260 additions
and
317 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const fakeFetch = id => | ||
new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve({id, name: `Id-${id}`}); | ||
}, 1000); | ||
}); | ||
|
||
const Fetcher = ({id}) => { | ||
const [name, setName] = React.useState(null); | ||
React.useEffect( | ||
() => { | ||
fakeFetch(id).then(response => { | ||
setName(response.name); | ||
}); | ||
}, | ||
[id] | ||
); | ||
|
||
return ( | ||
<div> | ||
<span> | ||
Fetcher {id}, name: {name} | ||
</span> | ||
</div> | ||
); | ||
}; | ||
const UpdateOnProps = () => { | ||
const [id, setId] = React.useState(0); | ||
|
||
return ( | ||
<div> | ||
<button onClick={() => setId(id + 1)}>Increment id</button> | ||
<Fetcher id={id} /> | ||
</div> | ||
); | ||
}; | ||
|
||
ReactDOM.render(<UpdateOnProps />, document.getElementById('root')); | ||
|
||
const logSize = () => { | ||
console.log(`updating, window size is ${window.innerWidth}`); | ||
}; | ||
|
||
const ShowWindowSize = () => { | ||
React.useEffect(() => { | ||
window.addEventListener('resize', logSize); | ||
return () => { | ||
window.removeEventListener('resize', logSize); | ||
}; | ||
}); | ||
|
||
return <div>Resize to log the window size</div>; | ||
}; | ||
const WithUnMount = () => { | ||
const [hidden, setHidden] = React.useState(false); | ||
return ( | ||
<div> | ||
<button onClick={() => setHidden(!hidden)}>Toggle</button> | ||
{hidden && <ShowWindowSize />} | ||
</div> | ||
); | ||
}; | ||
|
||
// ReactDOM.render(<WithUnMount />, document.getElementById('root')); |
Oops, something went wrong.