-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
onChange 用useCallback 包裹 ,onChange里面无法修改父组件的状态!把useCallback 干掉可以吗? #111
Comments
import "./styles.css";
import { useState } from "react";
import Alpha from "@uiw/react-color-alpha";
import { hsvaToRgbaString } from "@uiw/color-convert";
function Demo() {
const [hsva, setHsva] = useState({ h: 0, s: 0, v: 68, a: 1 });
const [obj,setObj] = useState({
name:"robin",
age:33
})
return (
<>
<Alpha
hsva={hsva}
onChange={(newAlpha) => {
setHsva({ ...hsva, ...newAlpha });
setObj({
...obj
})
}}
/>
{obj.name}
<button onClick={()=>{
setObj({
...obj,
name: "changedName"
})
}}>changeName</button>
<div
style={{
background: hsvaToRgbaString(hsva),
marginTop: 30,
padding: 10
}}
>
{JSON.stringify(hsva)}
</div>
</>
);
}
export default function App() {
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<Demo />
</div>
);
} |
先点击button 改变名字, 然后你再拖动 ,name 就变为初始值了,就是因为包了useCallback |
@RobinYang11 你拖动的时候,不是去改变了 |
我看了示例, |
你再刷新一下 我的例子 我改了,我增加了一个数组字段 |
jaywcjlove
added a commit
that referenced
this issue
Apr 12, 2023
@RobinYang11 Upgrade |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: