next-realworld-example-app
next-realworld-example-app copied to clipboard
Factor out new article vs edit article pages
They are mostly copy paste now:
- https://github.com/reck1ess/next-realworld-example-app/blob/66003772a42bf71c7b2771119121d4c9cf4b07d4/pages/editor/%5Bpid%5D.tsx
- https://github.com/reck1ess/next-realworld-example-app/blob/66003772a42bf71c7b2771119121d4c9cf4b07d4/pages/editor/new.tsx
I'm giving it a shot but stuck at some point, I wanted to do a this.props from getInitialProps to check new at:
import ArticleEditor from "../../components/editor/ArticleEditor";
export default function PublishArticleEditor() {
return (
<ArticleEditor new />
);
};
but I can't use this.props from there. Thinking is hard.
OK, I managed it as in: https://github.com/cirosantilli/cirodown/commit/8c05857c8f93c5269c8505427bb1bcec44f80769 by creating a function that returns a function.
I also made it use ArticleAPI.update in the component rather than raw axios.
Now I'm going to convert to the better new API getStaticProps + getStaticPaths since my repo is a fullstack integration.