Skip to content

Aleperix/next-hello-webapp

 
 

Repository files navigation

WebApp boilerplate with Next JS

Open in Gitpod

Requirements:

  • Make sure you are using node version 18
  1. Install the packages:
$ pnpm install
  1. Create a .env.local file:
$ cp .env.local.example .env.local
  1. Start coding! and the webpack dev server with live reload, for Windows, Mac, Linux, Gitpod or Codespaces:
$ pnpm run dev

Styles

You can update the styles/index.css or create new .css files inside styles/ and import them into your current scss or js files depending on your needs.

Components

Add more files into your ./src/components or styles folder as you need them and import them into your current files as needed.

Note (New changes): Components have been converted into functions to support the use of hooks:

  • Instead of a class component, we're using a const function.
  • Class constructor and state have been replaced by useState() hooks.
  • componentDidMount() was replaced by useEffect({}, []) - It runs at mount thanks to the second parameter ([]).
  • Actions and Store still work the same way.
// Previous "Class Oriented"
export class Demo extends React.Component {
	constructor(props) {
		super(props);

		this.state = getState('code here');
	}
}

// New "Functional Oriented"
export const Demo = () => (
	const [state, setState] = getState('code here'); //using the state (if needed)
  const { store, actions } = useContext(Context); // using the context (if needed)

);

💡Note: There is an example using the Context API inside ./src/app/demo/page.js;

Pages (Components)

Add more folders with a page.js file into your ./src/app

Context

This boilerplate comes with a centralized general Context API. The file ./src/context/flux.js has a base structure for the store, we encourage you to change it and adapt it to your needs.

React Context docs BreathCode Lesson view

The Provider is already set. You can consume from any component using the useContext hook to get the store and actions from the Context. Check src/app/demo/app.js to see a demo.

import { Context } from "@/context/appContext";
const MyComponentSuper = () => {
  //here you use useContext to get store and actions
  const { store, actions } = useContext(Context);
  return <div>{/* you can use your actions or store inside the html */}</div>
}

Publish your website!

  1. Vercel: The FREE recomended hosting provider is vercel.com, you can deploy in 1 minutes by typing the following 2 commands:

Login (you need to have an account):

$ pnpm i vercel -g && vercel login

Deploy:

$ vercel --prod

✎ Note: If you don't have an account just go to vercel.com, create a account and come back here.

Vercel example procedure to deploy

Contributors

This template was built as part of the 4Geeks Academy Coding Bootcamp by Alejandro Sanchez, Alexis Peña and many other contributors. Find out more about our Full Stack Developer Course, and Data Science Bootcamp.

About

WebApp boilerplate with Next JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 98.6%
  • CSS 1.4%