2020/01/28
npm create-next-app
npm install @zeit/next-css
const withCSS = require('@zeit/next-css');
module.exports = withCSS({});
import React from 'react';
import Head from 'next/head';
import { globalStyles } from '../styles/reset';
export default function MyApp({ Component, pageProps }) {
return (
<>
<Head>
<meta charSet="utf-8" />
<style type="text/css">{globalStyles}</style>
</Head>
<Component {...pageProps} />
</>
);
}
export const globalStyles = `
html,
body,
div,
span,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
abbr,
address,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
samp,
small,
strong,
sub,
sup,
var,
b,
i,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
font-weight: normal;
letter-spacing: 1px;
}
* {
box-sizing: border-box;
text-decoration: none;
list-style: none;
color: inherit;
}
*:focus {
outline: none;
border: none;
}
body {
line-height: 1;
}
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
nav ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: "";
content: none;
}
a {
margin: 0;
padding: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
/* change colours to suit your needs */
ins {
background-color: #ff9;
color: #000;
text-decoration: none;
}
/* change colours to suit your needs */
mark {
background-color: #ff9;
color: #000;
font-style: italic;
font-weight: bold;
}
del {
text-decoration: line-through;
}
abbr[title],
dfn[title] {
border-bottom: 1px dotted;
cursor: help;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/* change border colour to suit your needs */
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #cccccc;
margin: 1em 0;
padding: 0;
}
input,
select {
vertical-align: middle;
}
textarea {
resize: none;
}
input:focus {
outline:none;
border:0.5px solid #818181;
}
`;
npm install -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks @typescript-eslint/parser @typescript-eslint/eslint-plugin
{
"env": {
"browser": true,
"jest": true,
"es6": true
},
"plugins": ["import"],
"extends": ["plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
},
"rules": {
"no-console": "warn",
"no-eval": "error",
"import/first": "error"
},
// "parser": "babel-eslint"
}
npm install babel-eslint --save-dev
을 설치하고 위 코드 마지막 주석 처리 되어있는 "parser": "babel-eslint"
를 추가해준다.{
"window.zoomLevel": 0,
"emmet.includeLanguages": {
"erb": "html",
"ruby": "html"
},
"open-in-browser.default": "Chrome",
"workbench.colorTheme": "Atom One Dark",
"workbench.activityBar.visible": true,
"terminal.integrated.shell.osx": "/bin/zsh",
"editor.tabSize": 2,
"editor.detectIndentation": false,
"javascript.format.enable": false,
"editor.formatOnSave": true,
"[javascript]": {
"editor.formatOnSave": true
},
"prettier.disableLanguages": [
"js"
],
"eslint.alwaysShowStatus": true,
"files.autoSave": "onFocusChange",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"javascript.updateImportsOnFileMove.enabled": "never",
"liveServer.settings.donotVerifyTags": true,
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"javascript.implicitProjectConfig.experimentalDecorators": true
}
npm install mobx mobx-react
npm install --save-dev @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators
.babelrc
파일을 생성하고 아래 코드를 작성한다.{
"presets": ["next/babel"],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
}
ctrl + ,
(컨트롤+쉼표) / 맥이라면 커맨드+쉼표 를 한 후에 experimentaldecorators를 검색하여 설정을 해지하면된다.import { Provider } from 'mobx-react';
import CounterStore from '../stores/counter';
export default function MyApp({ Component, pageProps }) {
const counter = new CounterStore();
return (
<>
<Provider counter={counter}>
<Head>
<meta charSet="utf-8" />
<style type="text/css">{globalStyles}</style>
</Head>
<Component {...pageProps} />
</Provider>
</>
);
}
counter = new CounterStore()
라고 정의한 후에 Provider에 props로 전달하여 사용한다.import React, { Component } from 'react';
import { observer, inject } from 'mobx-react';
@inject('counter')
@observer
class Counter extends Component {
render() {
const { counter } = this.props;
return (
<div>
<h1>{counter.number}</h1>
<button onClick={counter.increase}>+1</button>
<button onClick={counter.decrease}>-1</button>
</div>
);
}
}
export default Counter;
// **** 함수형태로 파라미터를 전달해주면 특정 값만 받아올 수 있음.
@inject(stores => ({
number: stores.counter.number,
increase: stores.counter.increase,
decrease: stores.counter.decrease,
}))
@observer
class Counter extends Component {
render() {
const { number, increase, decrease } = this.props;
return (
<div>
<h1>{number}</h1>
<button onClick={increase}>+1</button>
<button onClick={decrease}>-1</button>
</div>
);
}
}