g0v/merityuan

Name: merityuan

Owner: g0v

Description: ????????? 2018/01/10 ????????????????

Created: 2018-01-13 02:05:31.0

Updated: 2018-01-13 09:27:35.0

Pushed: 2018-01-13 09:27:33.0

Homepage: https://g0v.github.io/merityuan/

Size: 1251

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

This project was bootstrapped with Create Next App.

Find the most recent version of this guide at here. And check out Next.js repo for the most up-to-date info.

Table of Contents
Questions? Feedback?

Check out Next.js FAQ & docs or let us know your feedback.

Folder Structure

After creating an app, it should look something like:

pp/
ADME.md
ckage.json
xt.config.js
mponents/
head.js
nav.js
ges/
index.js
atic/
favicon.ico

Routing in Next.js is based on the file system, so ./pages/index.js maps to the / route and ./pages/about.js would map to /about.

The ./static directory maps to /static in the next server, so you can put all your other static resources like images or compiled CSS in there.

Out of the box, we get:

Read more about Next's Routing

Available Scripts

In the project directory, you can run:

npm run dev

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any errors in the console.

npm run build

Builds the app for production to the .next folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

npm run start

Starts the application in production mode. The application should be compiled with `next build` first.

See the section in Next docs about deployment for more information.

Using CSS

styled-jsx is bundled with next to provide support for isolated scoped CSS. The aim is to support “shadow CSS” resembling of Web Components, which unfortunately do not support server-rendering and are JS-only.

rt default () => (
iv>
Hello world
<p>scoped!</p>
<style jsx>{`
  p {
    color: blue;
  }
  div {
    background: red;
  }
  @media (max-width: 600px) {
    div {
      background: blue;
    }
  }
`}</style>
div>

Read more about Next's CSS features.

Adding Components

We recommend keeping React components in ./components and they should look like:

./components/simple.js
t Simple = () => (
iv>Simple Component</div>


rt default Simple // don't forget to export default!
./components/complex.js
rt { Component } from 'react'

s Complex extends Component {
ate = {
text: 'World'


nder () {
const { text } = this.state
return <div>Hello {text}</div>



rt default Complex // don't forget to export default!
Fetching Data

You can fetch data in pages components using getInitialProps like this:

./pages/stars.js
t Page = (props) => <div>Next stars: {props.stars}</div>

.getInitialProps = async ({ req }) => {
nst res = await fetch('https://api.github.com/repos/zeit/next.js')
nst json = await res.json()
nst stars = json.stargazers_count
turn { stars }


rt default Page

For the initial page load, getInitialProps will execute on the server only. getInitialProps will only be executed on the client when navigating to a different route via the Link component or using the routing APIs.

Note: getInitialProps can not be used in children components. Only in pages.

Read more about fetching data and the component lifecycle

Custom Server

Want to start a new app with a custom server? Run create-next-app --example customer-server custom-app

Typically you start your next server with next start. It's possible, however, to start a server 100% programmatically in order to customize routes, use route patterns, etc

This example makes /a resolve to ./pages/b, and /b resolve to ./pages/a:

t { createServer } = require('http')
t { parse } = require('url')
t next = require('next')

t dev = process.env.NODE_ENV !== 'production'
t app = next({ dev })
t handle = app.getRequestHandler()

prepare().then(() => {
eateServer((req, res) => {
// Be sure to pass `true` as the second argument to `url.parse`.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true)
const { pathname, query } = parsedUrl

if (pathname === '/a') {
  app.render(req, res, '/b', query)
} else if (pathname === '/b') {
  app.render(req, res, '/a', query)
} else {
  handle(req, res, parsedUrl)
}

isten(3000, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')


Then, change your start script to NODE_ENV=production node server.js.

Read more about custom server and routing

Syntax Highlighting

To configure the syntax highlighting in your favorite text editor, head to the relevant Babel documentation page and follow the instructions. Some of the most popular editors are covered.

Deploy to Now

now offers a zero-configuration single-command deployment.

  1. Install the now command-line tool either via the recommended desktop tool or via node with npm install -g now.

  2. Run now from your project directory. You will see a now.sh URL in your output like this:

    ady! https://your-project-dirname-tpspyhtdtk.now.sh (copied to clipboard)
    

    Paste that URL into your browser when the build is complete, and you will see your deployed app.

You can find more details about now here.

Something Missing?

If you have ideas for how we could improve this readme or the project in general, let us know or contribute some!


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.