+ 7
I want to render a list with react
This is my try so far. Now I don't want to replace the items but to add https://code.sololearn.com/Wq1qqGgoyWBj/?ref=app
13 ответов
+ 7
Oma, this is where State comes in play.
https://code.sololearn.com/Wk6CiQedMyfK/?ref=app
+ 6
Something like this ?
function Exc(){
return(<React.Fragment><ul>{
excuses.map(el=>(
<li >{el}</li>
))
}
</ul>
</React.Fragment>);
}
function wand(){
var el = <Exc/>;
ReactDOM.render(el , document.getElementById('root'));
}
var theWand = setTimeout(wand, 500)
+ 6
Virtual DOM Is what makes react unique and better, I guess.
It uses these algorithms and compares two objects and updates only that part which is being updated.
So, even if we re render the list multiple times, it won't have to print them again and again and again.
My views on jQuery is clear shot, if you know modern JS good enough, jQuery is not needed.
+ 4
Abhay not so bad..
But now I always render the whole Fragment.
Can I simply add?
+ 4
Okay, so i modified it in a way that now it will add things to it.
+ 3
🔫 Rick Grimes yep...
Now I have to understand..but yes...
+ 2
Abhay
right I do.
But I re-render the list.
it might be optimized.
+ 2
🔫 Rick Grimes now add the items instead of replace
+ 1
Abhay after an interval
+ 1
Oma Falk but you are doing that already or am I missing something!
+ 1
🔫 Rick Grimes I wonder if react is the right choice.
As far as I understood it works with a virtual DOM.
Maybe JQuery is the better choice?
(Just in theory...I made it as react training)
Abhay ? What would u say?
+ 1
Oma Falk as far as i know jQuery makes things simpler by providing functions for tasks that we won't need to write in vanilla js again but react works on virtual dom updating only those elements whose states changes instead of updating the whole dom again which is really good for complex apps,and also provides component structure that can be reused and make things simple by providing use of jsx but to me it looks really difficult to make something different or simple but since I started with react few days ago so i can't tell much about the benefits or uses
0
Oma Falk like you are doing right now ,adding of items after some interval ? or adding them on some click!