Comments (9)
On the other hand, depending on what you need, this seems like overkill. You should be able to get away with applying :first-child
and :last-child
in CSS with no js needed.
from solid.
Two things here.
- Running
props.children
in component body "reads" the children, i.e. instantiates them outside of the context, and then you only put the child inside the context after it was initialized. - Use
children
helper in order for your component to stay reactive and instantiate children only once. (reading children once in component body will break reactivity). Rememberprops.children
will recreate children every time it is accessed.
from solid.
On the other hand, depending on what you need, this seems like overkill. You should be able to get away with applying
:first-child
and:last-child
in CSS with no js needed.
The Input
component only needs to add some classes when it is a child component of Compact
, and cannot be styled solely through first-child
and last-child
.
from solid.
Two things here.
- Running
props.children
in component body "reads" the children, i.e. instantiates them outside of the context, and then you only put the child inside the context after it was initialized.- Use
children
helper in order for your component to stay reactive and instantiate children only once. (reading children once in component body will break reactivity). Rememberprops.children
will recreate children every time it is accessed.
Using the children
helper has no effect on useContext
. The context received in Input
is always undefined
. The code above is just for illustration.
Using the same approach, it is possible to pass and receive context in React.
from solid.
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 compact
class if it is a child of compact, and then in css use .compact:first-child
?
from solid.
In Compact
, child components need to have unique styles by adding their respective -compact
classes, such as input-compact
and button-compact
. These styles should not be implemented in compact.scss
but rather in input.scss
or button.scss
, as -compact
may use some unique variables. For example, input-compact
needs to use var(--input-boder-radius)
, and input-compact:first-child
needs to use var(--input-border-radius-sm)
.
from solid.
That should be relatively easy:
Compact
renders a<CompactContext.Provider value={true}>
around its children (default isfalse
)- Children
const isCompact = useConext(CompactContext)
and render their respective.input-compact
or.button-compact
class (ifisCompact
) which you can also additionally style for.input-compact:first-child
etc.
from solid.
The class
I want to add is not only first-child
and last-child
, but also the size and shape of Input
and Button
when they are children of Compact
, which are also passed down from the context of Compact
.
from solid.
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.
from solid.
Related Issues (20)
- Cannot use istanbul ignore comments for generated code HOT 2
- setting element reference in `setStore` modifies the values in the array HOT 13
- `this` inside jsx-template inside a constructor of a derived class causes transformation-bug HOT 2
- The update of props is not granular enough. HOT 4
- No value attribute on CSR, but present in SSR
- Cannot properly bind numbers to Select HOT 3
- Double mounting for children element. HOT 2
- Is [email protected] active now? HOT 2
- Enhancement - Prop destructuring HOT 4
- [SSR/Astro] DOM Not Updated from State by Client Updates onMount HOT 5
- Boolean attributes HOT 5
- Component doesn't reliably respond to a signal after hydration HOT 3
- JSX does not wait for transitions to complete when using a ternary in a prop value HOT 4
- What is the minimum browser support for SolidJS? HOT 2
- TypeScript doesn't give error when calling a SetStoreFunction<T> where T is an array of objects HOT 13
- SyntaxError: The requested module 'node:events' does not provide an export named 'addAbortListener' HOT 4
- When `createResource` is used to load entities, and `createStore` is used to reference those entities, updates to store properties which reference entities should not mutate the original resource. HOT 1
- Attempted import error HOT 1
- Using enableScheduling in a simple solidjs-router project throws errors on transitions HOT 2
- [Bug?]: <noscript> content renders on the client HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solid.