next.js

Next.js Fetch data in HOC from server in SSG

泪湿孤枕 提交于 2020-08-27 06:38:59
问题 I created new app with Next.js 9.3.1 . In old app with SSR. I can you getInitialProps function in HOC components (not in page), so I can fetch data from server in HOC component and from page. Like this https://gist.github.com/whoisryosuke/d034d3eaa0556e86349fb2634788a7a1 Example : export default function withLayout(ComposedComponent) { return class WithLayout extends Component { static async getInitialProps(ctx) { console.log('ctxlayout fire'); const { reduxStore, req } = ctx || {} const

Next.js Fetch data in HOC from server in SSG

末鹿安然 提交于 2020-08-27 06:38:01
问题 I created new app with Next.js 9.3.1 . In old app with SSR. I can you getInitialProps function in HOC components (not in page), so I can fetch data from server in HOC component and from page. Like this https://gist.github.com/whoisryosuke/d034d3eaa0556e86349fb2634788a7a1 Example : export default function withLayout(ComposedComponent) { return class WithLayout extends Component { static async getInitialProps(ctx) { console.log('ctxlayout fire'); const { reduxStore, req } = ctx || {} const

next js Router.push reloads page

霸气de小男生 提交于 2020-08-25 07:32:09
问题 When I do Router.push my page reloads, I would expect pushState to be used. Using the following code in the component: import Router from "next/router"; //other code const search = useCallback( e => { e.preventDefault(); Router.push( `/products-search/${encodeURIComponent( searchText )}`, `/products-search?q=${encodeURIComponent( searchText )}` ); }, [searchText] ); //other code <form onSubmit={search}> <input type="text" onChange={change} value={searchText} pattern=".{3,}" title="3

next js Router.push reloads page

泪湿孤枕 提交于 2020-08-25 07:31:56
问题 When I do Router.push my page reloads, I would expect pushState to be used. Using the following code in the component: import Router from "next/router"; //other code const search = useCallback( e => { e.preventDefault(); Router.push( `/products-search/${encodeURIComponent( searchText )}`, `/products-search?q=${encodeURIComponent( searchText )}` ); }, [searchText] ); //other code <form onSubmit={search}> <input type="text" onChange={change} value={searchText} pattern=".{3,}" title="3

Cons of next.js over create react app + redux + ssr [closed]

China☆狼群 提交于 2020-08-24 05:14:01
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Improve this question I have developed an application using React + redux + EJS (with server side rendering) and its running fine in production. I have configured SSR + redux and all the code splitting stuff using webpack config. I have also implemented custom cache middleware

Cons of next.js over create react app + redux + ssr [closed]

老子叫甜甜 提交于 2020-08-24 05:13:19
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Improve this question I have developed an application using React + redux + EJS (with server side rendering) and its running fine in production. I have configured SSR + redux and all the code splitting stuff using webpack config. I have also implemented custom cache middleware

How to redirect to login page for restricted pages in next.js?

≯℡__Kan透↙ 提交于 2020-08-21 20:28:25
问题 In the udemy tutorial The Complete React Developer Course the additional package history was used to get the router outside a component for redirecting when the user is not authenticated: /* AppRouter.js */ import createHistory from "history/createBrowserHistory"; const AppRouter = () => ( <Router history={history}> <div> <Switch> <PublicRoute path="/" component={LoginPage} exact={true} /> <PrivateRoute path="/dashboard" component={ExpenseDashboardPage} /> <PrivateRoute path="/create"