-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat: 添加 useSafeState hook #826
Conversation
测试用例补一下? |
感觉叫 |
改了改了~ |
@awmleer 这个能合并么 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
要是没啥问题合一下? 不然我本地还得再维护一份代码 ~~~ @awmleer |
@@ -23,7 +23,10 @@ export default function useControllableValue<T>(props: Props = {}, options: Opti | |||
const value = props[valuePropName]; | |||
|
|||
const [state, setState] = useState<T | undefined>(() => { | |||
if (valuePropName in props) { | |||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不能改。
本来的逻辑是正确的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方会导致 defaultValue 不生效吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,这个地方的处理跟 antd 的处理有偏差吧,存在应该指的是初次值不为 undefined 的吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@awmleer @brickspert https://stackblitz.com/edit/react-nsofly?file=index.js 那 antd 的这个行为符合预期么 ~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brickspert 老哥 这个地方是不是再考虑一下?目前 antd 的组件(以及原生 input )针对首次 value 为 undefined 的时候 defaultValue 都会生效,按照 useControllableValue 目前的实现。无法跟 antd 完美的结合呀。~~
还有一些小问题,另外就是不要改 useControllableValue ~~ 感觉这个 Hooks 有点细碎,不确定会不会造成选择困难症。 |
避免组件卸载后,异步回调中执行 setState