vantui
vantui copied to clipboard
如果Tabbar通过active控制,会存在组件内current与外部active不一致情况
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @antmjs/[email protected]
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/@antmjs/vantui/es/tabbar/index.js b/node_modules/@antmjs/vantui/es/tabbar/index.js
index 30d4caf..f94bb34 100644
--- a/node_modules/@antmjs/vantui/es/tabbar/index.js
+++ b/node_modules/@antmjs/vantui/es/tabbar/index.js
@@ -43,16 +43,20 @@ export function Tabbar(props) {
"rectWrapper"
]);
const _change = useCallback(function(data) {
- setState((pre)=>{
- return _object_spread_props(_object_spread({}, pre), {
- current: data
+ // 受控模式通过useEffect更新current
+ if (active === null || active === void 0) {
+ setState((pre)=>{
+ return _object_spread_props(_object_spread({}, pre), {
+ current: data
+ });
});
- });
+ }
onChange === null || onChange === void 0 ? void 0 : onChange({
detail: data
});
}, [
- onChange
+ onChange,
+ active
]);
const newChildren = useMemo(()=>{
const tabs = parseTabList(children);
This issue body was partially generated by patch-package.