React key prop substitute!

I know what you're thinking, James, you silly sausage - Solid.js doesn't require keys for loops, and you're absolutely right but... I need key={} for another reason, I need to cause a component to be entirely unmounted and remounted, which was easily viable in React by just updating its key value in its parent. Any ideas how I can do that in Solid.js? Cheers, James
4 Replies
thetarnav
thetarnav9mo ago
<>{(signal() , <Component />)}</>
jimmyjamiejamesjimbob
it's not that I need to be able to toggle a component on/off - I need it to, on a single update be totally replaced by a new instance I can achieve that using a signal along the lines of:
const [shouldMount, setShouldMount] = useSignal(false);

function remount() {
setShouldMount(false);
setTimeout(() => {
setShouldMount(true);
});
}

return signal() && (
<Component />
);
const [shouldMount, setShouldMount] = useSignal(false);

function remount() {
setShouldMount(false);
setTimeout(() => {
setShouldMount(true);
});
}

return signal() && (
<Component />
);
but that causes the DOM to be totally removed for a split second whereas in React you can use key={whateverPrimitiveYouWant} to re-render a component, the reason I'm trying to do this is to recreate a bunch of components in my root.tsx (solid-start) for a page on router change - but I think I'll use a layout function and put that in each of the pages instead
thetarnav
thetarnav9mo ago
it's literally this it will rerun the component whenever the signal changes instantly you just need a signal to trigger a simple counter will do, or one with { equals: false } you also can use <Show keyed/> or <Rerun/> from solid-primitives for a similar effect
jimmyjamiejamesjimbob
oh right! strange syntax but I guess it makes sense, thank you!
Want results from more Discord servers?
Add your server
More Posts
Best way to dynamically access i18n-translations with typescriptHey folks, I am currently using @solid-primitives/i18n (https://github.com/solidjs-community/solid-i18n and context issuesHey folks, I am currently migrating to the 2.0.0 release of `@solid-primitives/i18n`. (https://gitDifference between `setState` and `produce`?I have `appState` as a store, and I'm trying to pass `appState.selectedTable` as a prop to a child cSolid Start not deploying on vercel in turborepoHi all, my solid start project doesn't deploy to vercel, aka every build fails. There are no error'Problem duplicating a component navigating with dynamic routingI am having difficulty causing a route component to be duplicated when navigating between a dynamic How to solve ts(2322) error on "each" attribute of "For" componentI'm trying to render items using the built-in "For" component for solid but I keep getting the folloHow to make array key in resource from useRouteData reactiveI'm noticing that, if the resource that is the return value of `useRouteData` is an object, then itscreateResource from the main layout causes it to completely crash the page# I have a `dashboard.tsx` main layout file and 2 routes inside this dashboard route, and inside thiRendering Solid inside another appI work as a web developer maintaining an organisation's web portal. The portal is quite old - it's bTesting state update after api call`Hello I am trying to test a `register user` component and I want to show an error message if I get a