Last active
April 29, 2021 02:14
-
-
Save atmartins/649514a67a2bdcc5002d99292755a6ed to your computer and use it in GitHub Desktop.
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
| import React from 'react'; | |
| type State = { | |
| isLoading: boolean; | |
| data: object; | |
| }; | |
| const initialState = { | |
| isLoading: true, | |
| data: undefined, | |
| } | |
| export const EditProgramMsgs = ({ id }) => { | |
| const [state, setState] = React.useState<State>(initialState); | |
| React.useEffect(() => { | |
| (async () => { | |
| let dataPromise: Promise<DataType>; | |
| if (id) { | |
| const d = await fetch(...); | |
| setState({ | |
| isLoading: false, | |
| data: d, | |
| }); | |
| } | |
| })(); | |
| }, []); | |
| if (state.isLoading) return <div className="section--loading">Loading...</div>; | |
| return ( | |
| <> | |
| { state.data.stuff } | |
| </> | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment