Code Monkey home page Code Monkey logo

pwa-nextjs-starter's Introduction

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.

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.