Khyonn
Khyonn
SSolidJS
Created by Khyonn on 7/3/2023 in #support
Is there some cases where createResource doesn't handle errors ?
Hello, I have this particular case where I'm fetching data based on searchParams and I have a basic error from the back-end:
const [baseUrl] = useContext(ARandomContext)
const [searchParams] = useSearchParams()
const source = () => ({ baseUrl: baseUrl(), params: { foo: searchParams.bar } })
const [data] = createResource(source, ({ baseUrl, params }) => api.get(baseUrl, params)) // Correct request URL / Params -> HTTP 404 ...
const [baseUrl] = useContext(ARandomContext)
const [searchParams] = useSearchParams()
const source = () => ({ baseUrl: baseUrl(), params: { foo: searchParams.bar } })
const [data] = createResource(source, ({ baseUrl, params }) => api.get(baseUrl, params)) // Correct request URL / Params -> HTTP 404 ...
My fetcher return a rejected promise, but it seems that it's not handled by createResource. I tryed to reproduce my case on a simpler example but I didn't succeed. I patched my issue using a catch manually in the createResource fetcher, but well ... I can't use native error handling mechanism (and ofc I could also have use ErrorBoundary but it didn't suit my needs) Anyway, all this context that brings me to my main question : what are the cases that make createResource not handling error
3 replies
SSolidJS
Created by Khyonn on 6/19/2023 in #support
Troubles Reading / Writing search params using solid-router useSearchParams()
Hello, I have some trouble reading/writing an array of search params using solid-router/useSearchParams() primitive
// for an URL like ?plop=a&plop=b
function MyComponent () {
const [searchParams, setSearchParams] = useSearchParams()
console.log(searchParams.plop) // 'b' when I wanted ['a', 'b']
return (
<button
onClick={() => {
setSearchParams({ pouet: ['a', 'b'] }) // update params like ?plop=a&plop=b&pouet=a%2Cb when I wanted ?plop=a&plop=b&pouet=a&pouet=b
}}>
Update search params
</button>
}
// for an URL like ?plop=a&plop=b
function MyComponent () {
const [searchParams, setSearchParams] = useSearchParams()
console.log(searchParams.plop) // 'b' when I wanted ['a', 'b']
return (
<button
onClick={() => {
setSearchParams({ pouet: ['a', 'b'] }) // update params like ?plop=a&plop=b&pouet=a%2Cb when I wanted ?plop=a&plop=b&pouet=a&pouet=b
}}>
Update search params
</button>
}
Do you have any tips to make it work ?
6 replies