Skip to content

Commit

Permalink
Merge pull request #534 from styfle/remove-createfactory
Browse files Browse the repository at this point in the history
Remove React.createFactory()
  • Loading branch information
styfle committed Mar 9, 2020
2 parents 6125794 + 28df6a9 commit 7cb62f6
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/pages/_document.ts → src/pages/_document.tsx
@@ -1,20 +1,13 @@
import { ServerResponse } from 'http';
import { createFactory } from 'react';
import React from 'react';
import { renderToNodeStream } from 'react-dom/server';

import IndexPage from '../pages/index';
import ResultPage from '../pages/result';
import ComparePage from '../pages/compare';
import NotFoundPage from '../pages/404';
import ServerErrorPage from '../pages/500';
import ParseFailurePage from '../pages/parse-failure';

const IndexFactory = createFactory(IndexPage);
const ResultFactory = createFactory(ResultPage);
const CompareFactory = createFactory(ComparePage);
const NotFoundFactory = createFactory(NotFoundPage);
const ServerErrorFactory = createFactory(ServerErrorPage);
const ParseFailureFactory = createFactory(ParseFailurePage);
import Index from './index';
import Result from './result';
import Compare from './compare';
import NotFound from './404';
import ServerError from './500';
import ParseFailure from './parse-failure';

import { getResultProps } from '../page-props/results';
import { getCompareProps } from '../page-props/compare';
Expand Down Expand Up @@ -161,19 +154,21 @@ async function routePage(pathname: string, query: ParsedUrlQuery, tmpDir: string
try {
switch (pathname) {
case pages.index:
return IndexFactory();
return <Index />;
case pages.parseFailure:
return ParseFailureFactory();
return <ParseFailure />;
case pages.result:
return (query.p || '').includes(',')
? CompareFactory(await getCompareProps(query, tmpDir))
: ResultFactory(await getResultProps(query, tmpDir));
return (query.p || '').includes(',') ? (
<Compare {...await getCompareProps(query, tmpDir)} />
) : (
<Result {...await getResultProps(query, tmpDir)} />
);
default:
return NotFoundFactory();
return <NotFound />;
}
} catch (e) {
console.error(`ERROR: ${e.message}`);
return ServerErrorFactory();
return <ServerError />;
}
}

Expand Down

1 comment on commit 7cb62f6

@vercel
Copy link

@vercel vercel bot commented on 7cb62f6 Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.