Skip to content

Zcehtro/pwa-nextjs-starter

 
 

Repository files navigation

POC: Nextjs + PWA + mui

MariaVla#1 https://pwa-nextjs-starter-kvuocxrq2-mariavla.vercel.app/login

  • React Query - fetching library
  • React Hook Forms - forms library
  • JSON Server for API mock
  • Material UI
  • i18n

TODO

  • Make login functional
  • React Query post example
  • Complete i18n
  • WebAuthn not working so far. Needs database?

Clone the repo and run:

yarn install
yarn dev

PWA

This example uses next-pwa based on Nextjs example -> https://github.com/vercel/next.js/tree/canary/examples/progressive-web-app

Issues encounter with next-pwa latest version: 5.5.5

Had to downgrade to next-pwa 5.5.4. Source: shadowwalker/next-pwa#383

Material UI

The project uses Next.js, which is a framework for server-rendered React apps. It includes @mui/material and its peer dependencies, including emotion, the default style engine in MUI v5. If you prefer, you can use styled-components instead.

The link component

Next.js has a custom Link component. The example folder provides adapters for usage with MUI. More information in the documentation.

Dependencies

  • nvm -v → 0.39.1

  • node -v → v18.7.0

  • npm -v → 8.15.1

  • yarn -v → 1.22.17

To run JSON server locally (our mock database) - Or use https://my-fake-json-server.herokuapp.com if working

$ yarn serve-json

This will create some endpoints define in the db.json where you can fetch data.

http://localhost:4000/superheroes http://localhost:4000/superheroes/:id http://localhost:4000/friends http://localhost:4000/friends/:id

You can also make post/put/delete requests. Example:

const createUser = () => {
  axios
    .post('http://localhost:4000/superheroes', {
      id: 4,
      name: 'The Flash',
      alterEgo: 'Barry Allen'
    })
    .then((resp) => {
      console.log(resp.data);
    })
    .catch((error) => {
      console.log(error);
    });
};

const updateUser = () => {
  axios
    .put('http://localhost:4000/superheroes/4', {
      name: 'Flash',
      alterEgo: 'Barry Allen'
    })
    .then((resp) => {
      console.log(resp.data);
    })
    .catch((error) => {
      console.log(error);
    });
};

const deleteUser = () => {
  axios
    .delete('http://localhost:4000/superheroes/4')
    .then((resp) => {
      console.log(resp.data);
    })
    .catch((error) => {
      console.log(error);
    });
};

API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.ts.

The pages/api directory is mapped to /api/*. Files in this directory are treated as API routes instead of React pages.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.6%
  • Other 1.4%