S
SolidJS9mo ago
Mathieu

Issue with reactivity when using mergeProps

https://playground.solidjs.com/anonymous/61802a1d-b0c8-44d9-9675-e6e73cdf36d3 In this demo, I do not understand why the last log says:
[Select] props.selectedOption {id: '2', name: 'bar'}
I expected undefined and if I remove the mergeProps call, the selected option will be undefined as expected. (note that the code itself doesn't make much sense but I removed as much code as possible from the real app)
14 Replies
mdynnl
mdynnl9mo ago
1. components only run once 2. accessing the value eagerly { selectedOption: props_.selectedOption } effectively make it static solution 1. getter mergeProps({ get selectedOption() { return props_.selectedOption }, ...) 2. accessor mergePrps(() => ({ selectedOption: props_.selectedOption }), ...)
Mathieu
Mathieu9mo ago
@mdynnl if static, why did the effect ran twice in Select? You may see the 2 logs in the Select, logging the value of props.selectedOption output the same value. Why did the effect ran the second time if the value didn't change?
mdynnl
mdynnl9mo ago
3. accessing via merged props will fallback if the value if undefined that combined with 2. also the reason it's reactive
Mathieu
Mathieu9mo ago
it's not intuitive I think @mdynnl when you say eagerly, I think you mean accessing early before something happens. What is it in this case?
mdynnl
mdynnl9mo ago
by this, do you mean the play tito posted?
Mathieu
Mathieu9mo ago
@Tito thank you, that is the accessor () => ({ ... }) solution of @mdynnl ? no I typed this before seeing Tito reply
mdynnl
mdynnl9mo ago
nah, i should've been clear let me update the old reply the props merged(through mergeProps) in Select will never fallback in this example
Mathieu
Mathieu9mo ago
so merging also adds a behaviour, so the "api" kinda changes. this is what I noted that it makes code less intuitive as I have to know, was this merged or not
mdynnl
mdynnl9mo ago
the merge isn't really a merge, it's a fallback falling back to the left from the right in the params of mergeProps
Mathieu
Mathieu9mo ago
I thought it would fallback only one time. but we can see that there is reactivity, and it's like a reactive fallback, where whenever the option is undefined, it will fall back (i.e. it's not ran only once, but it's reactive)
mdynnl
mdynnl9mo ago
well, props stay the same( just wrapped up with a proxy or merged into getters) i also don't get the intention here, mergeProps({ foo: props.foo }, props) mergeProps is basically saying if some prop on the right is undefined, use the one on the left adjacent
Mathieu
Mathieu9mo ago
but how when that reactive variable changes from a value to undefined, that code that does the fallback is ran again? So the mergeProps is not only ran once on mount, this code is ran subsequently somehow
mdynnl
mdynnl9mo ago
it's the same behavior as props is without mergeProps https://playground.solidjs.com/anonymous/52e51cda-aded-4666-9ed9-f28206653fa1 hence the confusion yeah, more like it
Mathieu
Mathieu9mo ago
@Tito there is reactivity because of selectedEntityId signal. I could make a dervied signal and pass it but that would be the same if I add a createEffect in the children, and I change selectedEntityId from the parent, the createEffect will run, because the props (selectedOption) is reactive (btw this becomes unrelated to the original question about mergePops and thank you so much both<3) Im not sure what you mean @Tito but check this: https://playground.solidjs.com/anonymous/6bb74459-6746-4ed5-9bae-c322d862386b I didn't do any kind of wrapping here @Tito btw why when I log console.dir(props.selectedOption) I cant see any getter or anything special, looks like a plain object literal ah cause again, the getter got ran, ahmmm
Want results from more Discord servers?
Add your server
More Posts
Regular Solid - the Correct way to use createResource?In my app, on my Dashboard view, I am using `createResource` to get my user data. I'm then just updSet Initial Route using @solidjs/routerHello, I have a simple Router setup with 3 routes/tabs inside my Main component ``` <Routes> <RoutIs it a good idea to make a real time chat app with SolidStart + ASP.NET?Hi. Me and a friend are making a real time chat app with solidjs and c#, first we tried with @microsProvider context isn't being executed on SSR website before child component?Hi, I'm working on a website for work and I'm attempting to insert a provider as the parent of a chCorrect method for passing form data between pagesFeeling like this is a super simple thing to do, I just cant figure it out from the docs. I have a fsolid-primitive/paginationcan somebody explain this?. here is the code of initiaze pagination. const [paginationProps, page] =Is it possible to have a route rerender only a portion of the page with Solid StartAs stated above I want to set up a page where sub routes rather than reloading the entire page just console.log asynch function delay the actual valuewhy console.log asynch function delay the actual value? . if no console.log i get the actual value. How to get previous route as search params?I tried <A> getting href before navigating from current path or route getting previous route from wiNesting startTransition calls arbitrarilyCan I nest `startTransition(() => { setState(); startTransition(() => setState()) })` calls arbitrar