S
SolidJS•13mo ago
akerbeltz

problem with "use:" and custom directives in tsx

I copied the custom directive from the docs
import { onCleanup } from 'solid-js';
export default function clickOutside(el, accessor) {
const onClick = (e) => !el.contains(e.target) && accessor()?.();
document.body.addEventListener('click', onClick);
onCleanup(() => document.body.removeEventListener('click', onClick));
}
import { onCleanup } from 'solid-js';
export default function clickOutside(el, accessor) {
const onClick = (e) => !el.contains(e.target) && accessor()?.();
document.body.addEventListener('click', onClick);
onCleanup(() => document.body.removeEventListener('click', onClick));
}
and then I used here like this
<div
class='select-component'
onClick={toggleDropdown}
use:clickOutside={() => setIsOpen(false)}
>
<div
class='select-component'
onClick={toggleDropdown}
use:clickOutside={() => setIsOpen(false)}
>
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>'.
4 Replies
Alex Lohr
Alex Lohr•13mo ago
You need to extend the solid-js namespace as explained here: https://www.solidjs.com/docs/latest/api#special-jsx-attributes - in your case the Directives interface. It's a bit hidden in the docs right now. We're working on them.
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
akerbeltz
akerbeltz•13mo ago
Oh thanks where i have to put that lines? where is the file to configure that?
high1
high1•13mo ago
You can do that in any file that's used for TS specific stuff, or you can create a new one Doesn't have to have a specific name, the extension needs to be .d.ts In vite samples, there's vite-env.d.ts It's a good candidate for this
akerbeltz
akerbeltz•13mo ago
@lexlohr @.high1 Thanks!! it worked 😄
Want results from more Discord servers?
Add your server
More Posts
Uncaught TypeError: _tmpl$6 is not a functionI'm trying to create a library that exposes a web component that's implemented internally with SolidCreateResource Not complete Fetch (promise) when page first loads, but completes when VsCode SavesHey I'm severely confused about what's happening under the hood for npm run dev. When I'm using creaHTTP trip, custom backendI was reading about this main idea of SSR, that it skips one step by fetching data and sending it frforce a dom update when updating a signal before the rest of the onMount functionin this code `csvColumns` is dependant on setData, how can I force the render update? ```jsx cAdd a ref and make it also exposableTo create a ref, I can write: ```jsx <input ref={ref} /> ``` In order to expose it to a parent compoRunning tests in docker fails, but works outside of dockerI am attempting to set up a Docker development environment for a SolidJS application using Docker CoBest way to implement a dialog in Solid.jsI'm using Solid.js for a library and need to implement a dialog to capture some user input (say, a sCannot find package 'solid-start-node' imported from 'solid-start/bin.cjs'I created a new project with `npm init solid@latest`, with the options [with-websocket], [ssr], [typNested routing not workingOne video is with npm, the other with pnpm Both not working, what am I doing wrong? cat.tsx ```tsx How to share .env files among NPM Workspaces?`.env` files are read from a workspace root folder (e.g. `/packages/foo-app/.env`), but the `.env` f