1.4.2 • Published 3 years ago

@grafoo/preact v1.4.2

Weekly downloads
48
License
MIT
Repository
github
Last release
3 years ago

@grafoo/preact

Install

$ npm i @grafoo/{core,react} && npm i -D @grafoo/babel-plugin

API

For documentation please refer to @grafoo/react's page since both modules share the same API.

Example

index.js

import { h, render } from "preact";
import createClient from "@grafoo/core";
import { Provider } from "@grafoo/preact";

import Posts from "./Posts";

function fetchQuery(query, variables) {
  const init = {
    method: "POST",
    body: JSON.stringify({ query, variables }),
    headers: {
      "content-type": "application/json"
    }
  };

  return fetch("http://some.graphql.api", init).then(res => res.json());
}

const client = createClient(fetchQuery);

render(
  <Provider client={client}>
    <Posts />
  </Provider>,
  document.getElementById("mnt")
);

Posts.js

import { h } from "preact";
import gql from "@grafoo/core/tag";
import { Consumer } from "@grafoo/preact";

const ALL_POSTS = gql`
  query getPosts($orderBy: PostOrderBy) {
    allPosts(orderBy: $orderBy) {
      title
      content
      createdAt
      updatedAt
    }
  }
`;

export default function Posts() {
  return (
    <Consumer query={ALL_POSTS} variables={{ orderBy: "createdAt_DESC" }}>
      {({ client, load, loaded, loading, errors, allPosts }) => (
        <h1>
          <marquee>👆 do whatever you want with the variables above 👆</marquee>
        </h1>
      )}
    </Consumer>
  );
}

LICENSE

MIT

1.4.2

3 years ago

1.5.1

3 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.0

6 years ago

0.0.1-beta.15

6 years ago

0.0.1-beta.14

6 years ago

0.0.1-beta.13

6 years ago

0.0.1-beta.12

6 years ago

0.0.1-beta.11

6 years ago

0.0.1-beta.10

6 years ago

0.0.1-beta.9

6 years ago

0.0.1-beta.8

6 years ago

0.0.1-beta.7

6 years ago

0.0.1-beta.6

6 years ago

0.0.1-beta.5

6 years ago

0.0.1-beta.4

6 years ago

0.0.1-beta.3

6 years ago

0.0.1-beta.2

6 years ago

0.0.1-beta.1

6 years ago

0.0.1-beta.0

6 years ago

0.0.1-alpha.17

6 years ago

0.0.1-alpha.16

6 years ago

0.0.1-alpha.15

6 years ago

0.0.1-alpha.14

6 years ago

0.0.1-alpha.13

6 years ago

0.0.1-alpha.12

6 years ago

0.0.1-alpha.11

6 years ago

0.0.1-alpha.10

6 years ago

0.0.1-alpha.9

6 years ago

0.0.1-alpha.8

6 years ago

0.0.1-alpha.7

6 years ago

0.0.1-alpha.6

6 years ago

0.0.1-alpha.5

6 years ago

0.0.1-alpha.4

6 years ago

0.0.1-alpha.3

6 years ago

0.0.1-alpha.2

6 years ago