nvm use
to use the correct node version.v16.17.1
. You can check your node version by running node -v
.yarn install
to install all the dependencies.yarn start
to start the app in development mode.yarn build
to build the app for production.yarn preview
to serve the app in production mode.docker build -t vite-ts-react-app .
to build the docker image.docker run -p 3000:3000 vite-ts-react-app
to run the docker image.docker-compose up
to run the docker image.export ENV=prod && docker compose up
to run the docker image.export ENV=prod TAG=1.0 && docker compose up
to run the docker image.yarn test:coverage
to generate the code coverage report.yarn test
to run the tests.yarn test:watch
to run the tests in watch mode.yarn codegen
to generate the GraphQL types.yarn codegen:watch
to generate the GraphQL types in watch mode.yarn commit
to commit the code.QueryFetchTemplate
- The QueryFetchTemplate component is used to handle render the loading, error and no data states for a query fetcher.
Example 1: Benefit of using with loadingContent
props is we don't need to worry about handle the null/undefined
check for the data.
const NoDataContent = () => <div>No Data</div>;
const LoadingContent = () => <div>Loading...</div>;
const DataContent = ({ listItems }: { listItems: any[] }) => (
<div>
{listItems.map(item => (
<div key={item.id}>{item.name}</div>
))}
</div>
);
const ExampleComponent = () => {
const { loading, data, error } = useGraphQLQuery(graphqlQuery, {
id: '1',
});
return (
<QueryFetchTemplate
loading={loading}
error={error}
data={data}
noDataContent={<NoDataContent />}
loadingContent={<LoadingContent />}
>
{({ data }) => <DataContent listItems={data} />}
</QueryFetchTemplate>
);
};
Example 2: Benefit of using without loadingContent
props is we can pass isLoading
value to all the children components while loading for the data.
const NoDataContent = () => <div>No Data</div>;
const Child1 = ({ isLoading, listItems }) => (isLoading ? <div>Loading..</div> : <div>{listItems[0]}</div>);
const Child2 = ({ isLoading, listItems }) => (isLoading ? <div>Loading..</div> : <div>{listItems[1]}</div>);
const DataContent = ({ isLoading, listItems }: { isLoading: boolean; listItems: any[] }) => (
<div>
<Child1 isLoading={isLoading} listItems={listItems} />
<Child2 isLoading={isLoading} listItems={listItems} />
</div>
);
const ExampleComponent = () => {
const { loading, data, error } = useGraphQLQuery(graphqlQuery, {
id: '1',
});
return (
<QueryFetchTemplate loading={loading} error={error} data={data} noDataContent={<NoDataContent />}>
{({ data, isLoading }) => <DataContent isLoading={isLoading} listItems={data} />}
</QueryFetchTemplate>
);
};