Replies: 11 comments 1 reply
-
Two things here.
|
Beta Was this translation helpful? Give feedback.
-
On the other hand, depending on what you need, this seems like overkill. You should be able to get away with applying |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
Using the Using the same approach, it is possible to pass and receive context in React. |
Beta Was this translation helpful? Give feedback.
-
Sorry I overlooked that the context is inside the for loop. I believe what you're trying to do is not possible because accessing children instantiates all of them, so there is no opportunity to inject a different context for each child. I don't have the full context of your application code, but I would strongly recommend not going for this pattern even if React supports it. You will be generating a different context each with two accessor functions for each child only to style first and last element differently. Could you perhaps add the |
Beta Was this translation helpful? Give feedback.
-
In |
Beta Was this translation helpful? Give feedback.
-
That should be relatively easy:
|
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
This is a good discussion. I'm going to move the issue there. It is behaving as expected. There is no bug here but I'm interested to see how a solution forms out. We do have this sort of chicken and the egg issue since you need to create the elements to iterate over them so there is no way to get context in to them before creating them. |
Beta Was this translation helpful? Give feedback.
-
Please take a look at this example. It should do everything you requested: https://playground.solidjs.com/anonymous/a63a01c0-446c-4424-a307-46cd58803319 |
Beta Was this translation helpful? Give feedback.
-
I was interested in this issue because this is what I exactly want to solve. But the above answer (#2084 (comment)) does not solve the issue with children but avoided the problem using CSS. My issue also is about iterating children and applying individual context based on the index of the children. I tried multiple approaches, but cannot find any working example.
this example is supposed to show
but never achieve the result because the Child component is never rendered after setting the UserContext's value is initialized in For component of ParentComponent. (but it uses the one in App component. if I don't wrap it in App component, it uses just 0 which is the default value of the UserContext)
When I see the console, it shows like this:
What is interesting here is, When I render component instead of {child} in the ParentComponent, it renders as expected. But This code is to illustrate the issue, not to render Child component. My real issue is a lot more complex. Also, when I don't even render {child} in the Parent component, still child is called and it will show no difference in the console.
I think this is a bug. Even though it is not a bug, it is a limitation of the context which makes this framework so hard to use IF there is no solution for this. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I want to add some classes to each child of Compact, but after running the above code, the context printed in the console is undefined, and I cannot figure out where the coding error is.
Your Example Website or App
Nope
Steps to Reproduce the Bug or Issue
I wrote three components.
Expected behavior
Input
should receive the data passed byCompact
through context.Screenshots or Videos
No response
Platform
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions