npx create-react-app 프로젝트명
yarn styled-components react-router-dom graphql react-apollo-hooks apollo-boost react-helmet
간단한 스타일 설정 예시
src/Styles/GlobalStyles.js
import { createGlobalStyle } from "styled-components";
import reset from "styled-reset";
export default createGlobalStyle`
${reset};
* {
box-sizing:border-box;
}
`;
src/Styles/Theme.js
const BOX_BORDER = "1px solid #e6e6e6";
const BORDER_RADIUS = "4px";
export default {
bgColor: "#FAFAFA",
blackColor: "#262626",
darkGreyColor: "#999",
lightGreyColor: "#c7c7c7",
redColor: "#ED4956",
blueColor: "#3897f0",
darkBlueColor: "#003569",
boxBorder: "1px solid #e6e6e6",
borderRadius: "4px",
whiteBox: `${BOX_BORDER};
${BORDER_RADIUS};
background-color:white;
`
};
src/Components/App.js
import React from "react";
import { ThemeProvider } from "styled-components";
import GlobalStyles from "../Styles/GlobalStyles";
import Theme from "../Styles/Theme";
export default () => (
<ThemeProvider theme={Theme}>
<GlobalStyles />
</ThemeProvider>
);
src/Routes 폴더를 만들고 이 안에 라우팅 할 파일들을 모두 넣는다.
이 파일들을 src/Components/Router.js 에서 불러다가 쓰고 여기서 export 한걸 App.js 에서 가져다가 쓴다.
react apollo 를 위한 세팅 예시
src/Apollo/Client.js
import ApolloClient from "apollo-boost";
import { defaults, resolvers } from "./LocalState";
export default new ApolloClient({
uri: "http://localhost:4000",
clientState: {
defaults,
resolvers
}
});
src/Apollo/LocalState.js
export const defaults = {
isLoggedIn: localStorage.getItem("token") !== null ? true : false
};
export const resolvers = {
Mutation: {
logUserIn: (_, { token }, { cache }) => {
localStorage.setItem("token", token);
cache.writeData({
data: {
isLoggedIn: true
}
});
return null;
},
logUserOut: (_, __, { cache }) => {
localStorage.removeItem("token");
window.location.reload();
return null;
}
}
};
src/index.js
import React from "react";
import ReactDOM from "react-dom";
import App from "./Components/App";
import Client from "./Apollo/Client";
import { ApolloProvider } from "react-apollo-hooks";
ReactDOM.render(
<ApolloProvider client={Client}>
<App />
</ApolloProvider>,
document.getElementById("root")
);
'미분류' 카테고리의 다른 글
prisma 알게 된 것들 (0) | 2019.07.30 |
---|---|
datamodel.prisma 예시 (0) | 2019.07.30 |
GraphQL 초기 프로젝트 설정 (0) | 2019.07.30 |