简体   繁体   English

姿势元素的孩子不响应姿势变化

[英]A posed element's child not responding to pose changes

AnimDiv does not appear to change its style as the pose variable changes. AnimDiv不会随着pose变量的改变而改变其样式。 The same approach would work with the parent, however the child seems to take only the initial value of whatever's passed to its pose , then doesn't care about it on subsequent re-renders. 父母也可以使用相同的方法,但是孩子似乎只接受传递给其pose的任何东西的初始值,然后不在乎随后的重新渲染。

Why is that so? 为什么会这样?

const AnimDiv = posed.div({
    red: {
        backgroundColor: "red"
    },
    blue: {
        backgroundColor: "blue"
    }
});

const AnimationTest = () => {
    const [pose, setPose] = useState("red");
    return (
        <div
            className="animated"
        >
            <AnimDiv
                style={{ position: "absolute", height: "20px", width: "20px" }}

                onClick={() => setPose(x => (x === "blue" ? "red" : "blue"))}
                pose={pose} // only the value from the initial render matters; you may change the pose state variable, but the element will not adjust its style
            ></AnimDiv>
        </div>
    );
};

EDIT: It does respond to pose changes, however for whatever reason it does not switch backgrounds. 编辑:它确实响应姿势变化,但是无论出于何种原因它都不会切换背景。 Opacity, for example, worked. 例如,不透明度起作用。

For background-color , the value be cannot be a color literal (such as red ). 对于background-color ,值be不能是颜色文字(例如red )。 Substituting a rgb(r,g,b) for it will make the pose work. 将其替换为rgb(r,g,b)将使姿势起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM