native-base Accordion Error with indexOf is not a function

Viewed 1372

I am new to React Native, so I apologize if this is a stupid question, but I am getting an error using the Accordion component from native-base. I gives me a message of "e.state.selected.indexOf is not a function".

I have the example code from the native-base docs pasted into a snack here to show the problem. Here is that code, it is pretty simple:

import React, { Component } from "react";
import { Container, Header, Content, Accordion, Text } from "native-base";

const dataArray = [
  { title: "First Element", content: "Lorem ipsum dolor sit amet" },
  { title: "Second Element", content: "Lorem ipsum dolor sit amet" },
  { title: "Third Element", content: "Lorem ipsum dolor sit amet" }
];

export default class AccordionExample extends Component {
  render() {
    return (
      <Container>
        <Header />
        <Content padder>
          <Accordion dataArray={dataArray} expanded={0}/>
        </Content>
      </Container>
    );
  }
}
1 Answers

The native-base package specified in the package.json is *, which fetches the latest stable version 2.15.2. This release seems to have a bug that requires you to pass expanded as an array.

You can find the discussion about this issue here.

Using the following syntax should fix the issue:

<Accordion dataArray={dataArray} expanded={[0]}/>

Alternatively, you could downgrade the version manually by setting an older version in the package.json file.

Related