Created
December 13, 2019 12:20
-
-
Save hijiangtao/0e794a60b7e44def90e92c0793d244d7 to your computer and use it in GitHub Desktop.
[BUG] Rax 小程序多次渲染间状态值更新错误问题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsx createElement */ | |
import { createElement, useEffect, useState } from 'rax'; | |
import View from 'rax-view'; | |
export default function App() { | |
const [stateParent, setStateParent] = useState(true); | |
const [stateChild, setStateChild] = useState(true); | |
useEffect(() => { | |
setStateChild(!stateChild); | |
}, [stateParent]); | |
function toggleParentChangeHandler() { | |
setStateParent(!stateParent); | |
} | |
console.log( | |
'stateParent 状态为', | |
stateParent, | |
'stateChild 状态为', | |
stateChild | |
); | |
return ( | |
<View> | |
<View | |
onClick={toggleParentChangeHandler} | |
> | |
点我更改 stateParent,从而触发 stateChild 变化 | |
</View> | |
<View | |
v-if={stateChild} | |
style={{ | |
border: '2rpx solid gray', | |
margin: '10rpx', | |
}} | |
> | |
<View> | |
只有当 stateChild 存在时才会显示 | |
</View> | |
<View> | |
当前 stateChild 状态为 {JSON.stringify(stateChild)}, stateParent 状态为 {JSON.stringify(stateParent)} | |
</View> | |
</View> | |
</View> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment