-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid unnecessary rerenders React components (#3124)
Co-authored-by: Ted Thibodeau Jr <[email protected]>
- Loading branch information
1 parent
7896fc5
commit c645932
Showing
15 changed files
with
481 additions
and
348 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'graphiql': patch | ||
'@graphiql/plugin-explorer': patch | ||
'@graphiql/react': patch | ||
--- | ||
|
||
avoid unecessary renders by using useMemo or useCallback |
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 |
---|---|---|
@@ -1,30 +1,29 @@ | ||
import ReactDOM from 'react-dom'; | ||
import { render } from 'react-dom'; | ||
import { GraphiQL } from 'graphiql'; | ||
import type { Fetcher } from '@graphiql/toolkit'; | ||
import { CSSProperties } from 'react'; | ||
|
||
const App = () => ( | ||
<GraphiQL | ||
style={{ height: '100vh' }} | ||
fetcher={async graphQLParams => { | ||
const data = await fetch( | ||
'https://swapi-graphql.netlify.app/.netlify/functions/index', | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(graphQLParams), | ||
credentials: 'same-origin', | ||
}, | ||
); | ||
return data.json().catch(() => data.text()); | ||
}} | ||
/> | ||
); | ||
const fetcher: Fetcher = async graphQLParams => { | ||
const data = await fetch( | ||
'https://swapi-graphql.netlify.app/.netlify/functions/index', | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(graphQLParams), | ||
credentials: 'same-origin', | ||
}, | ||
); | ||
return data.json().catch(() => data.text()); | ||
}; | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); | ||
const style: CSSProperties = { height: '100vh' }; | ||
|
||
const App = () => <GraphiQL style={style} fetcher={fetcher} />; | ||
|
||
render(<App />, document.getElementById('root')); | ||
|
||
// Hot Module Replacement | ||
if (module.hot) { | ||
module.hot.accept(); | ||
} | ||
module.hot?.accept(); |
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
Oops, something went wrong.