Skip to content

Commit

Permalink
updated: passing graphql client to props of all components
Browse files Browse the repository at this point in the history
  • Loading branch information
Salmandabbakuti committed Nov 20, 2021
1 parent 15b8d27 commit 5a29276
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
6 changes: 2 additions & 4 deletions client/src/Account.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useState, useEffect } from 'react'
import { GraphQLClient, gql } from 'graphql-request';

const client = new GraphQLClient(process.env.REACT_APP_API_URL || 'http:https://localhost:4000');
import { gql } from 'graphql-request';

export default function Account(props) {

const { client } = props;
const [loading, setLoading] = useState(true)
const [user, setUser] = useState({ firstName: '', lastName: '', phone: '', email: '' });

Expand Down
13 changes: 10 additions & 3 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { BrowserRouter, Route, Switch } from "react-router-dom";

import { GraphQLClient } from 'graphql-request';
import Home from "./Home";
import Account from "./Account";

const token = localStorage.getItem('TOKEN');
const client = new GraphQLClient(process.env.REACT_APP_API_URL || 'http:https://localhost:4000', {
headers: {
authorization: token ? `Bearer ${token}` : ''
}
});

export default function App() {
return (
<BrowserRouter>
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/user/:token" component={Account} />
<Route exact path="/" render={() => <Home client={client} />} />
<Route exact path="/user/:token" render={(props) => <Account {...props} client={client} />} />
<Route render={() => <h1>Not Found</h1>} />
</Switch >
</BrowserRouter>
Expand Down
11 changes: 2 additions & 9 deletions client/src/Home.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@

import { useState } from 'react'
import { GraphQLClient, gql } from 'graphql-request';
import { gql } from 'graphql-request';
import './index.css'

const token = localStorage.getItem('TOKEN');
const client = new GraphQLClient(process.env.REACT_APP_API_URL || 'http:https://localhost:4000', {
headers: {
authorization: token ? `Bearer ${token}` : ''
}
});

export default function Home() {
export default function Home({ client }) {
const [email, setEmail] = useState('');
const [loading, setLoading] = useState(false);

Expand Down

1 comment on commit 5a29276

@vercel
Copy link

@vercel vercel bot commented on 5a29276 Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.