Last active
February 22, 2020 01:52
-
-
Save bicknest/9542c4f9696f55fb8eff1b2605d5bd9f to your computer and use it in GitHub Desktop.
React-Admin -- Basic Profile Display App Example
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
import React, {Component} from 'react'; | |
import { Admin, Resource } from 'react-admin'; | |
import buildGraphQLProvider from 'ra-data-graphql'; | |
import ApolloClient from 'apollo-boost'; | |
import { buildQuery } from './buildQuery'; | |
import { uri } from './config'; | |
const client = ApolloClient({ uri }); | |
// The source for the TextFields correspond to fieldnames on the resource | |
const ProfileList = props => ( | |
<List {...props}> | |
<Datagrid> | |
<TextField source="name" /> | |
</DataGrid> | |
</List> | |
); | |
class App extends Component { | |
constructor() { | |
super(); | |
this.state = { dataProvider: null }; | |
} | |
componentDidMount() { | |
buildGraphQLProvider({ client, buildQuery }).then(dataProvider => | |
this.setState({ dataProvider }) | |
); | |
} | |
render() { | |
const { dataProvider } = this.state; | |
if (!dataProvider) { | |
return <div>Loading</div>; | |
} | |
return ( | |
<Admin dataProvider={dataProvider}> | |
<Resource name="Profile" list={ProfileList} /> | |
</Admin> | |
); | |
} | |
} | |
export default App; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment