Martnart
Martnart
Explore posts from servers
SSolidJS
Created by AesthetiCoder on 11/24/2023 in #support
how to put the types to the context
createContext accepts a generic type. You should pass the type of your context.
type ServerContext = {
serverContent: Store<ServerModel[]>
setServerContent: SetStoreFunction<ServerModel[]>
}
type ServerContext = {
serverContent: Store<ServerModel[]>
setServerContent: SetStoreFunction<ServerModel[]>
}
2 replies
SSolidJS
Created by Nathan on 10/20/2023 in #support
Typing nested routeData
You'll need to use RouteDataFuncArgs instead
2 replies
SSolidJS
Created by tozz on 9/23/2023 in #support
Best way of passing props from Provider to Context
If you do not intend to alter the data in any way, I guess your way is absolutely fine, that way you don't have to duplicate the data. Depending on your specific setup, you could also move the resource directly into the provider to begin with so you don't have to worry about the props.
6 replies
SSolidJS
Created by tozz on 9/23/2023 in #support
Best way of passing props from Provider to Context
This sounds like a store scenario to me.
export const DataGridProvider: Component<DataGridProviderProps> = (props) => {
const [markets, setMarkets] = createStore(props.markets)

const values = {
markets,
setMarkets,
};
export const DataGridProvider: Component<DataGridProviderProps> = (props) => {
const [markets, setMarkets] = createStore(props.markets)

const values = {
markets,
setMarkets,
};
Only problem here is timing in terms of initial data. You could wrap the provider with a Show when={markets()} to make sure initial data has loaded, or you can add an effect that updates the store when props.markets changes
createEffect(
on(
() => props.markets,
setMarkets(props.markets)
)
)
createEffect(
on(
() => props.markets,
setMarkets(props.markets)
)
)
Is that kind of what you are looking for? With a store you retain reactivity wherever you use it.
6 replies
SSolidJS
Created by Nin on 9/21/2023 in #support
Navigate user in login/logout functions
This is the way
5 replies
SSolidJS
Created by Nin on 9/21/2023 in #support
Navigate user in login/logout functions
Usually Contexts are part of a Provider component. If you did that, I think it would have the behavior that you want. Also a bit suspect that you have a session signal at the root level of the page. If you'd have it inside a Provider it'd be scoped as would be expected.
<AuthProvider>
...
<Routes />
...
</AuthProvider>
<AuthProvider>
...
<Routes />
...
</AuthProvider>
5 replies
SSolidJS
Created by Mathieu on 9/3/2023 in #support
Variable initialized in `onMount` becomes `undefined`
I meant that an effect returned from createEffect will execute before onMount Edit: Need to add that I am talking about an SSR context. Might well be not relevant for this particular use-case.
7 replies
SSolidJS
Created by Mathieu on 9/3/2023 in #support
Variable initialized in `onMount` becomes `undefined`
Might be too obvious (I guess you have checked that off already) but effects also run before mounting. so it's initially undefined.
7 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
🙂
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
Try return redirect('/login') > throw redirect('/login')
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
It should not return Response
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
What's your routeData look like?
20 replies
SSolidJS
Created by TicTacMan on 9/1/2023 in #support
Is it possible to pass paramters a function wrapped by a createEffect/createMemo?
If the parameters themselves are reactive you should just declare them as signals and have the memo listen to them:
const [param] = createSignal()

const value = createMemo(() => {
const theParam = param()
// doSomeThingWithParam()
}
const [param] = createSignal()

const value = createMemo(() => {
const theParam = param()
// doSomeThingWithParam()
}
If they are static you could do something like this:
const getMemo = (param) => createMemo(() => {
return (someSignal() || someComputation()) + param
}
const getMemo = (param) => createMemo(() => {
return (someSignal() || someComputation()) + param
}
2 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
Wait I just realize that your typing does seem to be off. That error shouldn't appear after a ? operator.
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
You could rewrite your when to actually return the output such as when={clans()?.invitations.length > 0 && clans()} and then work with the callback but it seems a bit cumbersome.
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
Specifically
// non-keyed w/o callback... - only updates the one expression, needs ! assertion
<Show when={user()}>
<div>{user()!.name}</div>
</Show>
// non-keyed w/o callback... - only updates the one expression, needs ! assertion
<Show when={user()}>
<div>{user()!.name}</div>
</Show>
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
Yes but it's another way of making TS think something. You are fine in this case to do a non-null-assertion. It is kind of encouraged to a certain degree since the latest <Show> update. It's just a bit hard to get the typing right. But whatever is guarded by a show, will be defined, basically.
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
Glad I'm not crazy 😄 I doubted myself there for a second
20 replies