首页 > 解决方案 > 分段控件 React Native

问题描述

我使用以下库:

https://github.com/react-native-segmented-control/segmented-control

Iv 按照说明进行安装,一切正常,但我无法更改值或保持状态以记录值:

    const [gender, setGender] = useState(0)


    <View style={styles.segmentContainer}>
        <SegmentedControl
            values={['Male', 'Female']}
            style={{height: 40}}
            fontStyle={styles.fontStyle}
            selectedIndex={gender}
            onChange={(event) => {
                setGender({selectedIndex: event.nativeEvent.selectedSegmentIndex});
            }}
        />
    </View>

我已经导入:

import { event } from 'react-native-reanimated';

每次我单击另一个选项时,应用程序都会崩溃并显示以下内容:

Invariant Violation: [18,472,{"type":"frames","frames":[0,0.10802469135802473,0.2098765432098766,0.30555555555555547,0.3950617283950617,0.4783950617283951,0.5555555555555555,0.6265432098765431,0.691358024691358,0.75,0.8024691358024691,0.8487654320987654,0.8888888888888888,0.9228395061728395,0.9506172839506173,0.9722222222222222,0.9876543209876543,0.9969135802469136,1],"toValue":"<<NaN>>","iterations":1},10261] is not usable as a native method argument

This error is located at:
    in RootErrorBoundary (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:45)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)

标签: reactjsreact-nativeuse-state

解决方案


推荐阅读