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.

Render Dynamic components without setting disableRecycling=true

See original GitHub issue

I am creating a RecyclerListView where the Items have a dynamic price ticker, so that on user event, the price ticker increments up. Currently the logic for a FeedItem.js is more or less:

import AnimateNumber   from 'react-native-countup'

export default class FeedItem extends Component {

	state = {
          walletValue      : 0
        , prevWalletValue  : 0
	}

	componentWillMount(){

		const walletValue = this.props.walletValue;
        this.setState({ 
              prevWalletValue : walletValue
            , walletValue     : walletValue
        })
	}

	invest = async () => {

		const update = await this.props.invest()

        if (!update)
            return false;

        if (update.hasOwnProperty('walletValue')){
            this.setState({ 
                  prevWalletValue: this.state.walletValue
                , walletValue    : update.walletValue 
            });
        }

	}

	renderTag = () => 
		<AnimateNumber 
			initial   = {this.state.prevWalletValue}
			value     = {this.state.walletValue}
			countBy   = {0.05}
		/>

	render = () => 
		<View>
			{this.renderTag()}
			<Button onPress = {this.invest} />
		</View>

}

Note there is a local state within each FeedItem that increments on user action. If I do not set disableRecycling=true, then the tag gets recycled when I scroll down and more FeedItems are loaded on refresh, this is concerning because the list is essentially rendering the first FeedItem’s price tag over and over again, and it’s only when the user presses the button, does the AnimatedNumber update to the new walletValue. Is there a way to prevent this behavior without setting disableRecycling=true and thus compromising performance?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
naqvitalhacommented, Sep 14, 2018

You shouldn’t have the state at component level. That will be difficult to handle. Can’t you simply store it at page level?

2reactions
tomLaddercommented, Sep 15, 2018

have the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to render components "dynamically" using ...
Say for example you want to build a customisable dashboard where your users can pick and choose the widgets they want displayed. See...
Read more >
Optimizing Flatlist Configuration
If your components have dynamic size and you really need performance, consider asking your design team if they may think of a redesign...
Read more >
Reconciliation
This article explains the choices we made in React's “diffing” algorithm so that component updates are predictable while being fast enough for high-performance ......
Read more >
Render dynamic components in ExtJS 4 GridPanel Column ...
If not, returns true to reschedule the task. If so, renders the component and returns false to cancel the task. We've had good...
Read more >
ListView - .NET MAUI
Define item appearance. The appearance of each item in the ListView can be defined by setting the ItemTemplate property to a DataTemplate :...
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