react-native-collapsible icon indicating copy to clipboard operation
react-native-collapsible copied to clipboard

Warning with another TouchableComponent

Open andrecbr opened this issue 5 years ago • 5 comments

I'm using react-native-paper with Accordion and when using a different touchableComponent it causes a warning:

<Accordion
  activeSections={activeSections}
  sections={sections}
  renderHeader={this._renderHeader}
  renderContent={this._renderContent}
  onChange={this._onChange}
  touchableComponent={TouchableRipple} // <-- here
/>

Warning: Failed prop type: Invalid prop `touchableComponent` of type `object` supplied to `Accordion`, expected `function`.

If I try the code below, it throws an exception:

<Accordion
  activeSections={activeSections}
  sections={sections}
  renderHeader={this._renderHeader}
  renderContent={this._renderContent}
  onChange={this._onChange}
  touchableComponent={() => <TouchableRipple />} // <-- Error
/>

Invariant Violation: React.Children.only expected to receive a single React element child.

"react": "16.9.0" "react-native": "0.61.5" "react-native-collapsible": "1.5.1"

andrecbr avatar Feb 14 '20 14:02 andrecbr

I am having the same issue

<Layout>
    <Accordion
        sections={props.data}
        renderHeader={header}
        renderContent={content}
        activeSections={[]}
        onChange={() => { }}
      />
</Layout>

"typescript": "3.6.3" "react": "16.9.0" "react-native": "0.62.0" "react-native-collapsible": "1.5.2"

JustinBeBoy avatar Apr 05 '20 14:04 JustinBeBoy

Here is my working code:

<Accordion
    sections={sectionList}
    activeSections={activeSections}
    renderHeader={renderHeader}
    renderContent={renderContent}
    touchableComponent={(props) => <TouchableOpacity {...props} />}
    onChange={(s) => setActiveSections(s)}
    sectionContainerStyle={styles.container}
/>

Don't forget to pass the props to you component, or it won't work.

pistou avatar Apr 08 '20 12:04 pistou

touchableComponent={(props) => <TouchableOpacity {...props} />}

but what if I don't want to add touchableComponent optional prop? I don't use it but have the same error message

ffastym avatar May 03 '20 13:05 ffastym

touchableComponent={(props) => <TouchableOpacity {...props} />}

but what if I don't want to add touchableComponent optional prop? I don't use it but have the same error message

touchableComponent={(props) => <TouchableHighlight {...props} />}

orzhtml avatar Jul 06 '20 04:07 orzhtml

I had to add @orzhtml workaround in order to remove the warning, which is weird because I wasn't using the optional prop touchableComponent . Probably an official solution is needed, right? This is how I was using the component:

<Accordion
   sections={sections}
   activeSections={activeSections}
   renderHeader={renderHeader}
   renderContent={renderContent}
   onChange={updateSections}
/>

And the warning:

Warning: Failed prop type: Invalid prop touchableComponent of type object supplied to Accordion, expected function`.

matias91 avatar Oct 08 '20 18:10 matias91