iRoachie / react-native-material-tabs

Material Design implementation of Tabs
MIT License
121 stars 56 forks source link

_this3.props.onChange is not a function #44

Closed ithustle closed 5 years ago

ithustle commented 5 years ago

I'm facing this error.

My code:

<MaterialTabs
                items={
                    [
                        <FontAwesome name={"home"} size={24} style={[styles.icons, { color: "#fff" }]}/>, 
                        <Icon name={"search"} size={24} style={[styles.icons, { color: "#fff" }]}/>, 
                        <Icon name={"genero"} size={24} style={[styles.icons, { color: "#fff" }]}/>, 
                        <Icon name={"minhas_musicas"} size={24} style={[styles.icons, { color: "#fff" }]}/>
                    ]
                }
                selectedIndex={this.state.selectedTab}
                onChange={this.setTab}
                barColor="#222"
                indicatorColor="#ff2a00"
                activeTextColor="#fff"
            />

Any help?

iRoachie commented 5 years ago

Did you define the setTab function you have there?

ithustle commented 5 years ago

Yep. Something like:

setTab = selectedTab => { console.log(selectedTab) this.setState({ selectedTab: 1 }); }

iRoachie commented 5 years ago

Can you show the whole example or recreate part of it on https://snack.expo.io that reproduces this?

ithustle commented 5 years ago

Oh damn! Shame on me... I've put setTab function inside render() ... My bad. Sorry. It's solved. Thanks for your time :)

iRoachie commented 5 years ago

All good! Glad you got it sorted out

ithustle commented 5 years ago

One more thing:

How can I avoid Warning: Encountered two children with the same key,null. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version. using components on items instead text?

iRoachie commented 5 years ago

In your items array, just add a key on to the items.

<FontAwesome name={"home"} size={24} style={[styles.icons, { color: "#fff" }]} key="home" />
ithustle commented 5 years ago

You rock!