Render Dynamic components without setting disableRecycling=true
See original GitHub issueI 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 FeedItem
s 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:
- Created 5 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You shouldn’t have the state at component level. That will be difficult to handle. Can’t you simply store it at page level?
have the same issue.