Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use React Hooks with react-native-tab-view

Tags:

react-native

red error screen 1

Cannot read property 'configureProps' of undefined

I was using the react-tab-view with react Hooks and typescript but I have some issues somebody could give me a hand...

import React, { useState } from 'react';
import { View, Text, TouchableOpacity, StyleSheet, Dimensions } from 'reactnative';
import { TabView, SceneMap } from 'react-native-tab-view';



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,
    },
});
like image 874
Felipe Vanegas Avatar asked Jul 15 '26 22:07

Felipe Vanegas


1 Answers

change

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

to

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

that should fix the error you are facing

like image 126
Adinnu Benedict Kingston Avatar answered Jul 18 '26 12:07

Adinnu Benedict Kingston