Giter VIP home page Giter VIP logo

react-relay-example's Introduction

React + Relay Example

List of Quotes with Authors implemented in React + Relay.

You can use either PHP or Node as a backend.

How to run the project

Installation

yarn install

# or if you use npm

npm install

Configuration

Create src/config.ts or rename src/config.example.ts and make sure it contains your server's graphql endpoint url:

export default {
  graphql: 'http://localhost:3013/graphql',
};

Download GraphQL schema

For this, you need to have graphql-cli installed.

graphql get-schema --project quotes -e default

Build / transform components which are using graphql / relay

yarn run relay

Start the project

yarn start

Old version

This version is using older Relay version 10.0.1:

Working version of React + Relay application written in JavaScript:

License

MIT license

react-relay-example's People

Contributors

juffalow avatar wpaczula avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-relay-example's Issues

useLazyLoadQuery vs usePreloadedQuery

First of all, thank you for your example, it helped me to get at least something from relay (as docs are sometimes controversial and not clear).

I found that in the migration guide they say that useLazyLoadQuery can be used.
However, in the useLazyLoadQuery description, they say
Instead, prefer usePreloadedQuery.
https://relay.dev/docs/api-reference/use-lazy-load-query/#uselazyloadquery

The problem with usePreloadedQuery to me is that it gets queryRef out of nowhere in all examples. They say I should handle it in routing, but I don't think react-router allows to do this.

Although it could be done like this

const WrappedHomePage = () => {
  const [queryRef, loadQuery] = useQueryLoader(HomePageQuery);

  useMemo(() => {
    loadQuery();
  }, [loadQuery]);

  return <HomePage queryRef={queryRef} />;
};

const HomePage = ({ queryRef }) => {
  const query = usePreloadedQuery(
    graphql`
      # By convention it should be <ComponentName></ComponentName>
      query HomePageQuery {
        ...HomePageContainer_repository
      }
    `,
    queryRef
  );

  return (
    <div>
      <HomePageContainer fragmentRef={query} />
    </div>
  );
};

I am not sure whether it is better at all. Could anyone suggest a solution of integrating it with react-router and use preloaded query?

Add tests

What an example it is without tests? Can someone help me and add tests for relay? Or any other kind of tests?

SSR streaming HTML, for SEO?

Any chance you'd want to update this example with SSR and streaming HTML?

So it will work well for regular sites that want SEO?

Currently Google's cached version of the page is empty (as it is a pure SPA): http://webcache.googleusercontent.com/search?q=cache:https://quotes.juffalow.com/

The other people who've done something towards this end, is:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.