Remix: Won't stop preserving state through rerouting to a nested route of the same Dynamic Segment

88 Views Asked by At

It may be because I'mm using 2 dynamic segments in a row, but i cant modify the database so I have to work around that.

Example: using V2_routing btw

~/routes/example.$id.$id2.jsx

import { useLoaderData, useParams } from "@remix-run/react";
import { json } from "@remix-run/node";
import { getExample } from "~/models/example.server.js;

export const loader = async ({params}) => {
   return json({ example: await getExample(params.id)});
};

export default function Example() {
   let { id2 } = useParams();
   let { example } = useLoaderData();

   return (
      <div>
         <p>{`${ id2 === "0" ? example.one : example.two }'}</p>
      </div>
   )
}

Theres times and things that will rerender when you navigate from say "/example/abc/1" to "/example/def/0" but many things won't. Specifically tags and defaultValues on an input.

I've tried initializing example to any empty object then setting it with useLoaderData. Thought I'd check if anyone had had this problem before I went insane trying to get state off the remix api with useEffect/fetch or trying to combine state management with the loader function.

0

There are 0 best solutions below