Cjmarkham
Cjmarkham

Reputation: 9700

React native export class and singleton method

I want to achieve something similar to how the Picker works in react native:

<Picker>
  <Picker.Item />
</Picker>

But am unsure how I would export the class to achieve this.

I currently have the following which I thought would work but I get an undefined react element error:

export default class extends React.Component {
  get Item () {
    return <Text>Foo</Text>;
  }

  render () {
    return <View></View>;
  }
}

React.createElement: type should not be null, undefined, boolean or number.

Upvotes: 0

Views: 1191

Answers (1)

jevakallio
jevakallio

Reputation: 35960

Here's the simplest way:

class Picker extends React.Component {
  //...
}

class Item extends React.Component {
  //...
}

Picker.Item = Item;

export default Picker;

Upvotes: 3

Related Questions