4.1.13 • Published 3 years ago

@before.js/client v4.1.13

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

@before/client

js-flybondi semantic-release js-semistandard-style code style: prettier

yarn add @before/client
yarn add @loadable/component react react-dom react-router-dom

Basic usage

// ./src/routes.js
import { asyncComponent } from '@before/client';
import loadable from '@loadable/component';

const Placeholder = () => <div>Loading</div>;

const HomeContainerLoader = /* #__LOADABLE__ */ () =>
  import(/* webpackChunkName: "home" */ './pages/HomeContainer/HomeContainer.page');

const routes = [
  {
    path: '/',
    exact: true,
    component: asyncComponent({
      LoadableComponent: loadable(HomeContainerLoader, { fallback: Placeholder }),
      loader: HomeContainerLoader
    })
  }
];

export default routes;
// ./src/client.js
import React from 'react';
import routes from './routes';
import { hydrate } from 'react-dom';
import { ensureReady, ensureClientReady, Before } from '@before/client';

ensureClientReady(() =>
  ensureReady(routes)
    .then(data => {
      hydrate(
        <BrowserRouter>
          <Before data={data} routes={routes} />
        </BrowserRouter>,
        document.getElementById('root')
      );
    })
  }
);
// ./pages/HomeContainer/HomeContainer.page'
import React, { useCallback } from 'react';

function HomePage({ history, location }) {
  const handleClick = useCallback(() => {
    history.push('/search/page');
  }, [history]);

  return (
    <main>
      <header>
        <h1>Home Page</h1>
      </header>
      <article>
        <section>
          <p>Hello actual pathname is {location.pathname}</p>
        </section>
        <a href="" onClick={handleClick}>Go to next page</a>
      </article>
    </main>
  );
}

Page props

Before will pass down the following props to your component plus all your component initial props:

NameDescription
historyCopy of react-router history but with custom push, replace and location properties. The original properties can we access with the unstable_ prefix.
queryObject with the querystring value from the location object if we are in the client or from the request query if we are in the server.
matchA match object contains information about how a matched the URL. More info
locationA location object shaped like { pathname, search, hash, state }
4.1.13

3 years ago

4.1.12

4 years ago

4.1.11

4 years ago

4.1.8

4 years ago

4.1.7

4 years ago

4.1.9

4 years ago

4.1.10

4 years ago

4.1.5

4 years ago

4.1.2

4 years ago

4.1.0

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago