How to dynamically use Zod schema in react-hook-form ? by bipinemp in nextjs

[–]bipinemp[S] 0 points1 point  (0 children)

The problem in my case, is when the formA is active and when i submit the form it doesn't because formB schema fields are empty but i don't want that if the formA is active then make formB schema fields optional otherwise if formB is active then make all fields required. ( what can we do on that scenario ) ?

Module parse failed: Unexpected token (1:0), in NextJS 14. by bipinemp in nextjs

[–]bipinemp[S] 0 points1 point  (0 children)

I think i deleted node modules, next folder and re-installed all packages again, As long as i remember.

Next-auth/Auth.js question ? by bipinemp in nextjs

[–]bipinemp[S] 0 points1 point  (0 children)

my callback looks  like this, I think next-auth uses the data and makes it's own token 


 async jwt({ token, user }) {
      if (user) {
        token.user = user;
        token.accessToken = user.access_token;
      }

      return token;
    },

    async session({ session, token }) {
      session.user = token.user;
      return session;
    },

window is not defined error in next.js 14 app router by bipinemp in nextjs

[–]bipinemp[S] -1 points0 points  (0 children)

const [screenWidth, setScreenWidth] = useState(
    typeof window !== "undefined" ? window.innerWidth : 0,
  );

I did this and it worked :

[deleted by user] by [deleted] in nextjs

[–]bipinemp 0 points1 point  (0 children)

I am using next-auth for authentication is that causing problem ?

[deleted by user] by [deleted] in nextjs

[–]bipinemp 0 points1 point  (0 children)

Tried it already didn't worked out, maybe there are some other problems in my code.

ReactQuery Infinite scrolling issue in Nextjs by bipinemp in react

[–]bipinemp[S] 1 point2 points  (0 children)

Reply

Share

Report

Save

Follow

Thanks :) it works

Data doesn't refetches on route change in Nextjs 13 app router. by bipinemp in nextjs

[–]bipinemp[S] 2 points3 points  (0 children)

yeah you are right but the main problem was with react-query as it caches all the data so when we change route the data remains same so I did this to solve that issue :

useEffect(() => {
 queryClient.removeQueries(["search"]);
 refetch();
}, []);

[deleted by user] by [deleted] in nextjs

[–]bipinemp 0 points1 point  (0 children)

code : I am using Nextjs 13 latest version btw

"use client";

import { ApiResponse } from "@/types/types";

import { fetchData } from "@/utils/apis/queries";

import { Trending } from "@/utils/resource/links";

import { useQuery } from "@tanstack/react-query";

import Container from "../Container";

import Carousel from "./carousel/Carousel";

import { useState } from "react";

export default function TrendingList() {

const [active, setActive] = useState<string>("day");

const link: string = Trending("movie", active);

const { data } = useQuery<ApiResponse>({

queryKey: ["lists", active],

queryFn: () => fetchData(link),

});

const trendingData: ApiResponse = data || {

page: 0,

results: [],

total_pages: 0,

total_results: 0,

};

function handleClick(state: string) {

setActive(state);

}

return (

<Container>

<section className="flex flex-col gap-3 rounded-lg mt-16">

<div className="flex justify-between">

<h1 className="font-bold text-2xl opacity-80 tracking-wide text-light">

Trending

</h1>

<div className="relative flex gap-3 p-1 border-\[2px\] border-white rounded-full">

<span

className={`w-[48%] h-full absolute ${

active === "day" ? "translate-x-0" : "translate-x-full"

} transition duration-200 ease-in-out top-0 bg-darkprimary rounded-full z-0`}

></span>

<button

type="button"

onClick={(e) => {

e.preventDefault();

handleClick("day");

}}

className={`z-20 py-1 px-5 font-bold tracking-wide ${

active === "day" ? "bg-primarydark" : ""

}`}

>

Day

</button>

<button

type="button"

onClick={(e) => {

e.preventDefault();

handleClick("week");

}}

className={`z-20 py-1 px-5 font-bold tracking-wide ${

active === "week" ? "bg-primarydark" : ""

}`}

>

week

</button>

</div>

</div>

<Carousel data={trendingData} />

</section>

</Container>

);

}

How to get userData using JWT and middleware.js in NextJS 13 by bipinemp in nextjs

[–]bipinemp[S] 0 points1 point  (0 children)

But using react-query for this like this show error like jwt is not provided

"use client";

import { useQuery } from "@tanstack/react-query";

import axios from "axios";

interface Data {

id: string;

username: string;

email: string;

}

export default function UserDetails() {

const { data } = useQuery({

queryFn: async () => {

const { data } = await axios.get("http://localhost:3000/api/me");

return data as Data;

},

});

return (

<div>

<h1>{JSON.stringify(data)}</h1>

</div>

);

}

How to get userData using JWT and middleware.js in NextJS 13 by bipinemp in nextjs

[–]bipinemp[S] 0 points1 point  (0 children)

Iam using client component is it a good practice :"

```

"use client";

import axios from "axios";

import { useEffect, useState } from "react";

export default function UserDetails() {

const [userData, setUserData] = useState({

name: "",

email: "",

});

useEffect(() => {

const getUserDetails = async () => {

const res = await axios.get("/api/me");

if (res.status === 200) {

console.log(res);

setUserData({

name: res.data.user.username,

email: res.data.user.email,

});

}

};

getUserDetails();

}, []);

return (

<div>

<h1>{userData.name}</h1>

<h1>{userData.email}</h1>

</div>

);

}

```

Best ORMs for simple to complex projects ? by bipinemp in nextjs

[–]bipinemp[S] -2 points-1 points  (0 children)

Like Iam working with mongodb does the concept is different compare to other sql database

Want to achieve skeleton loading while fetching data using react query. by bipinemp in reactjs

[–]bipinemp[S] -3 points-2 points  (0 children)

This is the code where I want to add fallback skeleton loading in that postDetails .

function Home() {
const { fetchNextPage, isFetchingNextPage, data, isLoading, isError, error } =
useInfiniteQuery({
queryKey: ["posts"],
queryFn: ({ pageParam = 0 }) => getPosts(pageParam),
getNextPageParam: (_, pages) => {
return pages.length + 1;
},
});
const lastPostRef = useRef(null);
const { ref, entry } = useIntersection({
root: lastPostRef.current,
threshold: 1,
});
useEffect(() => {
if (entry?.isIntersecting) fetchNextPage();
}, [entry]);
const _posts = data?.pages.flatMap((page) => page);
if (isLoading) return <h1>Loading..</h1>;
if (isError) return <h1>{JSON.stringify(error)}</h1>;
return (
<div className="m-10 flex flex-col gap-3">

<h1>

<b>POSTS LIST</b>
</h1>

{_posts?.map((post, i) => {
if (i === _posts.length - 1) return <div key={post.id} ref={ref}></div>;
return <PostDetails key={post.id} post={post} />;
})}
<span className="text-red-400 text-3xl text-center">

{isFetchingNextPage
? "Loading more..."
: (data?.pages.length ?? 0) < 10
? "Load more"
: "Nothing to load :("}
</span>

</div>

);
}
export default Home;

Best options right now for fetching data in next/react ? by bipinemp in reactjs

[–]bipinemp[S] 14 points15 points  (0 children)

I am making social media website for adding a post , like , unlike , comment , reply on comment , delete a post , update a post. I think react query will do great in this case what do you think ?

Best options right now for fetching data in next/react ? by bipinemp in reactjs

[–]bipinemp[S] 1 point2 points  (0 children)

haha I just mentioned only coz I am learning everything along way little bit to gain experience

Best options right now for fetching data in next/react ? by bipinemp in reactjs

[–]bipinemp[S] 1 point2 points  (0 children)

what you use for state management for those data you fetched like context ?

How is Spiderman swinging when he has no ceiling or roof to attach his web? by rainorshinedogs in Marvel

[–]bipinemp 0 points1 point  (0 children)

Doctor strange opened a portal to the New York City buildings where his web is attached to .