0.0.26 • Published 3 years ago

react-hydrate-query v0.0.26

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
3 years ago

Install

npm install react-hydrate-query
yarn add react-hydrate-query

External dependencies

react
axios

Usage

Server

import { ServerProvider } from "react-hydrate-query";

<ServerProvider hydrateState={myServerState}>
  <App />
</ServerProvider>

Html

<html>
  <head>
    <script
        dangerouslySetInnerHTML={{
          __html: `window.HYDRATE_STATE=${JSON.stringify(myServerState)}`
        }}
      />
  </head>
  <body>
    <div
      id="root"
      className="root"
      dangerouslySetInnerHTML={{ __html: content }}
    />
    {scripts}
  </body>
</html>

Client

import { hydrateRoot } from "react-dom/client";
import { ClientProvider } from "react-hydrate-query";

const container = document.getElementById("root");
hydrateRoot(container, <ClientProvider>
    <App />
</ClientProvider>);

useHydrateState

//Gets data from ssr
import { useHydrateState } from "react-hydrate-query";

const [state, setState] = useHydrateState({ key: "test" });
  • key - window.HYDRATE_STATE object field

useHydrateQuery

//Gets data from ssr, if they are missing executes the request
import { useHydrateQuery } from "react-hydrate-query";

const [state, setState, isLoading] = useHydrateQuery({ key: "test", url: "/api/test", params: {} });
  • key - window.HYDRATE_STATE object field
  • url - request url (only post available now)
  • params - request params
  • onError - error handler (Axios Error)
0.0.26

3 years ago

0.0.25

3 years ago

0.0.24

3 years ago

0.0.23

3 years ago

0.0.22

3 years ago

0.0.21

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago