Skip to content
Advertisement

Tag: next.js

Clicking on next/link causing an issue in getInitialProps

I’m trying to add a link to redirect users to the create page, But when I clicked on the link I got the following error: Link code : getInitialProps // _app.tsx Answer You have to write isomorphic code inside MyApp.getInitialProps because that code can run both on the server (during first page load) or on the client (during client-side navigations).

Is it nessesary to use getStaticProps with json import in Next.js?

I want to render static data that is coming from a JSON or typescript file and display it to the user. Do I have to use getStaticProps or can I simply import the data without getStaticProps? It’s not clear to me after reading the next documentation. projects.tsx names.json index.tsx Answer It’s totally up to you which approach you are going

Css not loading properly in Reactjs

I am working in reactjs and using (Nextjs) framework,I have All “css,js,images” in “public” folder and in “_app.js” i included all these files,But i whenever i tyring to open “Main page” in browser then page is not displaying (only loader showing) , In other words, webpage not displaying properly Here is my code in “_app.js”,Where i am wrong ? Answer

Updating the localStorage is not in sync

When I toggle darkmode it doesn’t update in _app unless I have 2 tabs opened and trigger it in one tab, then the other tab gets updated and darkmode is toggled, but not the tab I pressed the toggle. I use useSettings in both index and _app. I recorded a video so it’s easier to see what’s going on: https://youtu.be/W5du7Y-457Y.

Can’t mock the navigator.language

I’m currently adding unit test for some of shard utils functions. I’m kinda new to unit testing. Currently having hard time to mock some global object. Is there any way to mock/update value of navigator.language? It is always returning en-US. I tried the Object.defineProperty and different jest mock objects. Didn’t work. The thing is, if I console.log(navigator.language) in the test,

How to redirect to another page using on keypress in nextjs?

I need to redirect users using onkeypress in nextjs. I have a search input where users can type and then press enter key to go to the other page. What I’ve tried: i would appreciate your help. Answer You can use the useRouter hook from next – https://nextjs.org/docs/api-reference/next/router Try changing you handler to

How to render data from parse in next-auth

I want to render data in client side below from parse after signin from next auth using useSession But it’s just render email This is my callbacks code And client side code I don’t know how to change my callbacks code to display data from database Answer After a while and try harder, I was successful to render data. Just

Advertisement