React: NextJS FrameWork
8914 단어 React
https://nextjs.org/docs 이 프레임 워 크 는 route 대신 파일 디 렉 터 리 를 사용 할 수 있 으 며,lazyloading 을 자동 으로 사용 합 니 다.React 코드 내용;
페이지 폴 더 의 파일 만 path 입 니 다.나머지 component 는 그대로 사용 합 니 다.
component 부분 style 진행
import React from 'react';
const user= (props)=> (
<div>
<h1>{props.name}</h1>
<p>Age: {props.age}</p>
<style jsx>
{`
div{
broder:1px solid #eee;
box-shadow:0 2px 3px #ccc;
padding:20px;
text-align:center;
}`}
</style>
</div>
);
export default user;
error handle
pages 에 구축error.js
getInitialProps(context)
서버 에서 render 하기 전에 비동기 작업 하기;
class IndexPage extends Component{
static getInitialProps(context){ // server console
console.log(context);
const promise = new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve({appName:'Super App'});
},1000);
});
return promise;
}
function component 에서 호출
import React from 'react';
import User from '../../components/User';
const authIndexPage = (props) => (
<div>
<h1>The Auth Index Page - {props.appName}</h1>
<User name="Max" age={28}/>
</div>
);
authIndexPage.getInitialProps = (context)=>{
console.log(context);
const promise = new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve({appName:'Super App(Auth)'});
},1000);
});
return promise;
};
export default authIndexPage;
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
바삭바삭하고 간단한 결제 페이지 만들기먼저 Next.js에서 프로젝트를 만듭니다. Vercel & Next.js가 매우 편하기 때문에 최근에는이 구성을 사용하고 있습니다. 그런 다음 Tailwind CSS를 넣습니다. Tailwind CSS를 사용하면 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.