Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

感觉ahooks可以把信号量整合进来,类似于@preact/signal中的几个方法 #2221

Closed
1075488066 opened this issue Jun 16, 2023 · 4 comments

Comments

@1075488066
Copy link

@preact/signal
signal

import { useSignal, useComputed } from "@preact/signals-react";

function Counter() {
	const count = useSignal(0);
	const double = useComputed(() => count.value * 2);

	return (
		<button onClick={() => count.value++}>
			Value: {count.value}, value x 2 = {double.value}
		</button>
	);
}
@liuyib
Copy link
Collaborator

liuyib commented Jun 17, 2023

你是希望 preact 的 signal, signal.peek, computed, effect, batch 这些 hook 都整合进来?还是只整合某几个 hook?但是我看除了 useSignal 在 react 中都有与之对应的 hook 了呀。

想要使用与 useSignal 相同能力的 hook,可以使用 ahooks 的 useReactive,用法一致的。

有其他更好的整合进来的建议吗?感觉和 react 原生提供的 hook 能力都重复了 @1075488066

@liuyib liuyib added the needs more info Needs more information to continue label Jun 17, 2023
@github-actions
Copy link

Hi, 1075488066.

It seems that this issue is a bit vague and lacks some necessary information.

看起来这条 issue 描述得有些模糊,缺少一些必要的信息。

@1075488066
Copy link
Author

主要是希望在写watch功能时不用自己手动添加依赖。

@liuyib
Copy link
Collaborator

liuyib commented Jun 18, 2023

主要是希望在写watch功能时不用自己手动添加依赖。

这个能力要寄希望于 react 官方来实现了,ahooks 作为一个 hook 库,实现不了


另外,把 useEffect 当成 watch 来用,不是特别好的 react 编码实践,不太推荐。

可以参考官方的文档:You Might Not Need an Effect 把滥用 useEffect 的地方优化掉,然后你会发现,自己几乎不会再被什么 watch 不 watch 的心智负担所缠绕。

@liuyib liuyib removed the needs more info Needs more information to continue label Jun 18, 2023
@liuyib liuyib closed this as completed Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants