How to pass signals to native dom elements props? #435
-
Hello, Here is an example const ButtonWithLoading = ({ onClick, children }: { onClick: () => Promise<unknown>; children: ReactNode }) => {
console.log("ButtonWithLoading render");
const loading = useSignal<boolean>(false);
const onClickWithLoading = async () => {
loading.value = true;
await onClick();
loading.value = false;
};
return (
<button onClick={onClickWithLoading} disabled={loading.value}>
{children}
</button>
);
}; Is there a way to pass the return useComputed(() => (
<button onClick={onClickWithLoading} disabled={loading.value}>
{children}
</button>
)); |
Beta Was this translation helpful? Give feedback.
Answered by
rschristian
Nov 11, 2023
Replies: 1 comment 2 replies
-
The component is refreshing because you're using
Ignoring the irrelevant TS type assertion, that should work just fine, per the example above. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
rschristian
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The component is refreshing because you're using
loading.value
. Use justloading
, as we outline in our docs.Here's an example
Ignoring the irrelevant TS type assertion, that should work just fine, per the example above.