akerbeltz
Explore posts from serversTTCTheo's Typesafe Cult
•Created by akerbeltz on 6/25/2024 in #questions
json schema to yup raw version
I am trying to get the raw yup object with the chaining functions from a json schema. Tried some libraries but didn't know how to get the raw yup.
From that json schema i expect to get something like this:
2 replies
TTCTheo's Typesafe Cult
•Created by akerbeltz on 2/9/2024 in #questions
npm dependencies and peerDependencies
2 replies
TTCTheo's Typesafe Cult
•Created by akerbeltz on 11/20/2023 in #questions
virtual keyboard on mobile making scroll of the page
How can I prevent the virtual keyboard from causing the page to scroll when clicking outside of an input field? Currently, on some mobile devices, when the text field is filled and the keyboard is visible, clicking a button results in the keyboard disappearing faster than the click event can be registered.
This leads to unintentional clicks on other buttons, which is quite unexpected.
I've attempted various solutions without success so far. Any suggestions or code snippets are greatly appreciated.
2 replies
Persist routes between reloads with @solidjs/router
It's strange but for some reason when i do a reload ( with an f5 for example), the direction changes to the root direction. Before, in other apps it persisted the route direction. Any ideas of what it can be?
3 replies
TTCTheo's Typesafe Cult
•Created by akerbeltz on 10/4/2023 in #questions
Difference between HEAD^ and HEAD~
What's the difference in git between HEAD^ and HEAD~ ?
specially in these two commands:
git reset --soft HEAD~
git reset HEAD^
Also, what would be the best way to undo a commit and what would be the best way to undo a commit and a push ?
2 replies
Spinner component questions about best practices
What would be the best way to show a spinner only if a loading() signal spends more than 2 seconds (that is when a resource). I'm thinking setting that on the Spinner component directly but there's a better way?
Also the spinner usually appears on each page of the app centered so I created a prop that wraps it in a div and centers it, rendered conditionally with the wrapper or alone, what do you thing?
3 replies
typing CreateResource
I would like to do something like this so typescript don't show an error when using it in jsx:
const [data, { mutate }] = createResource<{ dataExample: string } | undefined>(() =>
getData("/api/Example")
);
So i can do:
<p>{data()?.dataExample}</p>
44 replies
How to reload a component in solidjs (a route or a specific component) (I'm using solidjs/router)
I need to be able to reload a component clicking a button or reload the whole route page clicking another button. I want the same functionality like doing a window.location.reload but more specific with a router page or a component.
8 replies
Validating a field based on promise values min and max with yup and react form handler
const schemaReference = (res) => {
console.log(res);
return yup.object({
unit: yup.string().required('Required'),
reference: yup
.number()
.typeError('Reference must be a number')
.min(res.min, 'must be in the range ' + res.min +"-"+ res.max)
.max(res.max, 'must be in the range ' + es.min+"-"+ res.max)
.required('Required'),
});
};
const getMinMax = async () => {
let res = await initialData;
let min = await res.data.parameters.min;
console.log(min);
let max = await res.data.parameters.max;
console.log(max);
return { min, max };
};
const formHandler = useFormHandler(yupSchema(schemaReference(getMinMax())));
This is the code on the body of a component. I want to basically pass a variable that is the response of an http request (so this is a promise and that implies a lot of async awaits everywere). Reading the doc of yup and solid form handler i didn't find a way to do that
3 replies
TTCTheo's Typesafe Cult
•Created by akerbeltz on 7/5/2023 in #questions
icon in mobile app
When i am on chrome and click on the Add to home screen the icon that appears is a "1" instead of the logo of my app.
I have created a manifest.json the same way you would do in a react app and the meta tags of html seems ok too.
Any suggestion what can i do?
2 replies
signal of createResource is not reactive inside a For component
When passing the signal obtained in a request made by createResource and looping the results of that the reactivity when the resource mutate is lost.
It works fine if i iterate the signal with a .map() so i don't know what can be the issue.
24 replies
TTCTheo's Typesafe Cult
•Created by akerbeltz on 6/14/2023 in #questions
Union types to solve magic strings problems
With the union types of typescript you are solving the problems of magic strings ? Or it's better to make an object?
5 replies
checkbox controlled from outside
I want to control a checkbox from the outside and expose either a function onChange and the props.checked that will be reactive.
import { createSignal } from 'solid-js';
import c from './Switch.module.scss';
function SwitchButton(props) {
return (
<div
style={{
display: 'flex',
}}
>
<div style={{ 'align-self': 'center' }}>{props.label1}</div>
<label class={c.switch}>
<input
type={'checkbox'}
class={c.input}
checked={props.checked}
onChange={(e) => props?.onChange?.(e)}
/>
<span class={c.slider}></span>
</label>
<div style={{ 'align-self': 'center' }}>{props.label2}</div>
</div>
);
}
export default SwitchButton;
29 replies
problem with "use:" and custom directives in tsx
I copied the custom directive from the docs
and then I used here like this
But it marks as a error when I use it like that in the tsx file. It works correctly as expected tho. Is there any way to get rid of the wavy red line ?
The error says:
Type '{ children: Element[]; class: string; onClick: () => void; "use:clickOutside": () => false; }' is not assignable to type 'HTMLAttributes<HTMLDivElement>'. Property 'use:clickOutside' does not exist on type 'HTMLAttributes<HTMLDivElement>'.
9 replies
Websockets on Solidjs
I have some code in React for websocket conexion in components, I tried to port the code to solidjs, but no success yet.
Any idea of how would look this to work correctly? the idea of the websockets is to update an http resource (I think I'll use the mutate of the createResource API)
35 replies
How to implement an ErrorHandle to wrap the handle error and loading of a resource?
I want to handle both the error and loading of a resource in the same component to wrap a page with this comonent so it renders a message error when there's one and loading when it's loading.
Something like that but don't get the right sintax.
1 replies
If the prop array can be an object or a string. Which method would you use ?
This is the code that renders the props.items that prop can be either an array of objects with a text titles and an icon or only an array of text titles.
Also how would you do validation ? The code i wrote works correctly but there's a better way?
<Index each={props.items}>
{(item, index) => (
<A
href={
props.hrefRoot +
(typeof item() === "string" ? item() : item().text)
}
activeClass="router-link-active"
inactiveClass=""
class="carousel-item"
>
<Show when={item().icon}>
<span class={"icon icon-" + item().icon} />
</Show>
{typeof item() === "string" ? item() : item().text}
</A>
)}
</Index>
2 replies