Coder Social home page Coder Social logo

react-cell's Introduction

react-cell

npm bundlephobia Misaka

๐Ÿ”‹ Declarative React Components that fetch GraphQL. Inspired by Redwood Cells, using Apollo Client.

Getting started

yarn add react-cell

Features

  • ๐Ÿฑ Structured declaration for components
  • ๐Ÿ“˜ First-class TypeScript support
  • ๐Ÿš€ Apollo-based GraphQL queries
  • โšก Only peer dependencies

Usage

import cell from 'react-cell';
import { gql } from '@apollo/client';

interface NovelCellProps {
  title: string;
}

const QUERY = gql`
query($title: String) {
  novel(title: $title) {
    title
    description
  }
}`;

// props are passed onto the query as variables
const NovelCell = cell<{ novel: Novel }, NovelCellProps>(QUERY, {
  Success({ novel }) {
    return (
      <div>
        <h1>{novel.title}</h1>
        <h1>{novel.description}</h1>
      </div>
    );
  },

  // While your query is executing.
  Loading: () =>
    <div>Loading...</div>,

  // Renders if your query results in null or an empty array.
  Empty: () =>
    <div>Found nothing.</div>,

  // This renders if your query results in an error.
  Failure: ({ error }) =>
    <div>Error: {error.message}</div>
});

<NovelCell title="Title here">

react-cell's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

tubbo

react-cell's Issues

Allow passing options to useQuery

I would like to use polling to have a 'reactive' cell. The current implementation does not support this. I propose allowing to pass a third, optional argument that gets used as 'options' argument for the useQuery apollo hook.

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.