如何在react-native-tab-view中使用React Hooks

时间:2019-03-18 20:14:55

标签: react-native

enter image description here Cannot read property 'configureProps' of undefined我正在使用带有react Hooks和打字稿的react-tab-view,但是我遇到了某些问题,有人可以帮忙...

从'react'导入React,{useState};     从'react-native'导入{View,Text,TouchableOpacity,StyleSheet,Dimensions};     从'react-native-tab-view'导入{TabView,SceneMap};

const FirstRoute = () => (
    <View style={[styles.scene, { backgroundColor: '#ff4081' }]} />
);
const SecondRoute = () => (
    <View style={[styles.scene, { backgroundColor: '#673ab7' }]} />
);

interface Props {
    navigation: any;

}
export default function Home(props: Props) {


    const [rar, setRar] = useState({
        index: 0,
        routes: [
            { key: 'first', title: 'First' },
            { key: 'second', title: 'Second' },
        ]
    });

    var NativeAppEventEmitter = require('RCTNativeAppEventEmitter');
    return (
        <View>
            <TouchableOpacity onPress={props.navigation.openDrawer}>
                <Text>hola desde home</Text>
            </TouchableOpacity>

            <TabView
                navigationState={rar}
                renderScene={SceneMap({
                    first: FirstRoute,
                    second: SecondRoute,
                })}
                onIndexChange={index => ({ index })}
                initialLayout={{ width: Dimensions.get('window').width, height: 250 }}
            />


        </View>
    )
}
const styles = StyleSheet.create({
    scene: {
        flex: 0.3,
    },
});

2 个答案:

答案 0 :(得分:0)

更改

onIndexChange={index => ({ index })}

onIndexChange={index => setRar({ ...rar, index })}

应该解决您面临的错误

答案 1 :(得分:-1)

next

相关问题