9.2.3 • Published 5 months ago

fridge-next v9.2.3

Weekly downloads
4
License
MIT
Repository
github
Last release
5 months ago

Installation

$ npm install --save fridge-next next react react-dom

Examples

How to use

Setup

Add a fridge API configuration to next.config.js:

const withFridge = require("fridge-next/config");

module.exports = withFridge({
  fridge: {
    token: "xxxxxxxxxx",
  },
});

Usage

getStaticProps

import { fridge } from "fridge-next";

export async function getStaticProps({ params }) {
  const content = await fridge(`content/${params.id}`);

  return {
    props: { content },
  };
}

Hook

import React from "react";
import { useFridge } from "fridge-next";

const Footer = () => {
  const { data: settings } = useFridge("content/settings");

  return <footer>{!!settings && <p>{settings.copyright}</p>}</footer>;
};

Render Function

There is also a <FridgeContent> component which accepts a render function as its child. You can provide a query prop with can be a string or array of strings of queries to pass to Fridge.

import { FridgeContent, HtmlContent } from "fridge-next";

export default ({ id }) => (
  <FridgeContent query={`content/team_member/${id}`}>
    {(teamMember) => (
      <div>
        <h3>{teamMember.name}</h3>
        <HtmlContent content={teamMember.bio} />
      </div>
    )}
  </FridgeContent>
);

Custom Routes

SSR

Provide a routes object in next.config.js:

routes: {[path: string]: string | {page: string, query: Object}}

module.exports = {
  routes: {
    "/blog/:slug": "/blog",
    "/*": { page: "/page", query: { fallback: "true" } },
  },
};

Export

Use exportPathMap in next.config.js to provide custom routes. These routes are intended for use with fridge export, however if you specify useExportRoutes: true in next.config.js then these routes will be added in production:

module.exports = {
  exportPathMap: async (fridge, defaultPathMap) => {
    const members = await fridge.get("content/team_member");
    for (const member of members) {
      defaultPathMap[`/team/${member.slug}`] = {
        page: "/team",
        query: { id: member.id },
      };
    }
    return defaultPathMap;
  },
};

Now

Set target: "serverless" in next.config.js.

Add custom routing to now.json:

{
  "version": 2,
  "builds": [{ "src": "next.config.js", "use": "@now/next" }],
  "routes": [
    { "src": "/", "dest": "/" },
    { "src": "/blog/(?<slug>[^/]*)", "dest": "/blog?slug=$slug" },
    { "src": "/team/(?<id>[^/]*)", "dest": "/team?id=$id" }
  ]
}

Note: If you are deploying to a serverless environment, you don't need custom SSR routes.

Next.js

We use next.js internally to power everything, see their docs for further customization next.js

9.2.3

5 months ago

9.2.2

5 months ago

9.2.1

11 months ago

9.2.0

2 years ago

9.1.0

3 years ago

9.0.2

3 years ago

9.0.1

3 years ago

9.0.0

3 years ago

8.1.2

3 years ago

8.1.1

3 years ago

8.1.0

4 years ago

8.0.0

4 years ago

8.0.0-beta.0

4 years ago

7.0.6

5 years ago

7.0.5

5 years ago

7.0.4

5 years ago

7.0.3

5 years ago

7.0.2

5 years ago

7.0.1

5 years ago

7.0.0

5 years ago

7.0.0-beta2

5 years ago

7.0.0-beta1

5 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.0.3

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.2.0

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.0

7 years ago

0.1.0-beta2

7 years ago

0.1.0-beta

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago