mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-31 18:07:00 +02:00
refactor(v2): use react hooks on root app (#1095)
* refactor(v2): use functional component + react hooks for App * docusaurus/link * nits * review
This commit is contained in:
parent
72d1fa2d2a
commit
8695ed89a6
23 changed files with 65 additions and 58 deletions
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import React, {useState} from 'react';
|
||||
import {renderRoutes} from 'react-router-config';
|
||||
|
||||
import routes from '@generated/routes'; // eslint-disable-line
|
||||
|
@ -27,23 +27,13 @@ const data = {
|
|||
siteConfig,
|
||||
};
|
||||
|
||||
class App extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
setContext: context => {
|
||||
this.setState(context);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<DocusaurusContext.Provider value={{...data, ...this.state}}>
|
||||
{renderRoutes(routes)}
|
||||
</DocusaurusContext.Provider>
|
||||
);
|
||||
}
|
||||
function App() {
|
||||
const [context, setContext] = useState({});
|
||||
return (
|
||||
<DocusaurusContext.Provider value={{...data, ...context, setContext}}>
|
||||
{renderRoutes(routes)}
|
||||
</DocusaurusContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue