question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component inside Tab won't re-render when a prop changes its value.

See original GitHub issue

Issue type

I’m submitting a …

  • bug report
  • feature request

Issue description

Current behavior: When a component prop inside <Tab /> is updated via the redux store, the component doesn’t re-render.

Expected behavior: The component should re-render when the prop changes.

Steps to reproduce: Add component inside a <Tab />

Related code:

<TabView
    selectedIndex={this.state.selectedIndex}
    onSelect={this.handleTabSelect}
    style={[styles.tabView]}
    tabBarStyle={[styles.tabBarView]}
    indicatorStyle={[styles.tabIndicator]}
>
    <Tab title="Tab 1" titleStyle={[styles.tabTitle, this.state.selectedIndex === 0 && styles.tabTitleSelected]}>
        ...
    </Tab>

    <Tab title="Tab 2" titleStyle={[styles.tabTitle, this.state.selectedIndex === 1 && styles.tabTitleSelected]}>
        ...
    </Tab>

    <Tab title="Tab 3" titleStyle={[styles.tabTitle, this.state.selectedIndex === 2 && styles.tabTitleSelected]}>
        ...
    </Tab>

    <Tab title="Tab 4" titleStyle={[styles.tabTitle, this.state.selectedIndex === 3 && styles.tabTitleSelected]}>
        <MyCustomComponent propFromRedux={propFromRedux} />
    </Tab>
</TabView>

The MyCustomComponent won’t re-render when propFromRedux change its value. To make sure that the problem is not in MyCustomComponent, I’ve moved it outside the <TabView /> and when the propFromRedux changed, the component re-rendered.

Other information:

OS, device, package version

OS: iOS 12
Device: iPhone Xs
Package version: 4.0.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
NBoychevcommented, Jul 10, 2019

Thanks! I was just testing this on your playground and it worked.

Keep up the great work!

1reaction
32penkincommented, Jul 10, 2019

@NBoychev sorry for the misunderstanding. I just used the “master” version of the framework, so everything worked for me 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component rerenders when state has not changed on the ...
Save this question. Show activity on this post. I have a tabs component that changes state every time a different tab is clicked....
Read more >
When does React re-render components? - Felix Gerschau
Want to see re-rendering in action? React DevTools lets you highlight renders under Components -> View Settings -> Highlight updates when ...
Read more >
5 Ways to Avoid React Component Re-Renderings
1. Memoization using useMemo() and UseCallback() Hooks. Memoization enables your code to re-render components only if there's a change in the props. With...
Read more >
Learn how to force react components to rerender without ...
You can change the value of the key prop, and it will make React unmount and re-mount the component again, and go through...
Read more >
useMemo - React Docs
A list of dependencies including every value within your component that's ... a re-render is slow, you can tell List to skip re-rendering...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found