Giter Site home page Giter Site logo

react-ssg-data-demo's Introduction

deploy with vercel deploy with netlify

react-ssg-data

this an example with react-router-dom in Static site generation

note: this is not targets CSS Optimization, Redux, Mobx, etc. targets react-router-dom and static data fetching

Features

  • Code splitting
  • Static site generation
  • Hot reload
  • React-router-dom

Installation

$ git clone https://github.com/healthpackdev/react-ssg-data
$ npm install

Development

$ npm run dev

Go localhost:3000 or http://localhost:{process.env.port}

Mentioned in you can also development the server.

Production

$ npm run build

this builds the server and client then runs npm run export your static files will be generated din ./dist

Analyze

$ npm run analyze

Analyze with Statoscope


add a new page

to the first add your route to ./src/routes.ts

const routes: Route[] = [
  {
    path: '/',
    exact: true,
    component: importPage('index'),
  },
  {
    path: '/profile',
    component: importPage('profile'),
  },
  {
    path: '/404',
    component: importPage('404'),
  },
  {
    path: '/nested/page',
    component: importPage('nested/page'),
  },
  // add like this
  {
    path: '/my/new/page',
    component: importPage('my/new/page'),
  },
];

then create a ./src/pages/my/new/page.tsx or .js, .jsx

const myNewPage = () => (
  <div>
    <h1>My New Page</h1>
  </div>
);

export default myNewPage;

if you want to load a static data for page create a ./src/data/my/new/page.tsx or .js, .jsx

const myNewPageData = () => {
  return {
    myNewPageData: getMyNewPageData(),
  };
};

export default myNewPageData;

then use with

import { useRouteData } from '@/lib/use-route-data';

const myNewPage = () => {
  const { myNewPageData } = useRouteData();

  <div>
    <h1>My New Page {myNewPageData}</h1>
  </div>;
};

export default myNewPage;

Known issues

Hot reload: not working with css files.

License

MIT

react-ssg-data-demo's People

Contributors

healthpackdev avatar

Watchers

 avatar

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.