#React Components – Zero To Hero Series – Part 2 by Vipul Jain cc @CsharpCorner #ReactJS

#React Components - Zero To Hero Series - Part 2 by Vipul Jain cc @CsharpCorner  #ReactJS

  • This is the second article in the ReactJS – Zero to Hero Series.
  • I recommend reading the first article (link given below), before going through this article.
  • In this article, we will see the explanation of React Components.
  • Components are the fundamental units of a React application.
  • Now, with this basic understanding, in the next articles, we will see more about Populating Props, Composing components, State, Default props and Validating props.

This is the second article in ReactJS – Zero to Hero Series. I will recommend you read the first article (link given below), before going through this article.
Continue reading “#React Components – Zero To Hero Series – Part 2 by Vipul Jain cc @CsharpCorner #ReactJS”

Key concept and Its necessities in React component – Shubham Akodiya – Medium

Key concept and Its necessities in React component  #es6 #react #reactjs

  • /ChildKey’;class ParentKey extends Component { constructor() { super(); this.state = {activeIndex: 0}; } updateIndex = () = { const {activeIndex} = this.state; this.setState({activeIndex: activeIndex + 1}) }getContent() { const {activeIndex} = this.state; let element; switch(activeIndex) { case 0: element = ChildKey name=’abc’ updateData={this.updateIndex} / break; case 1: element = ChildKey…
  • getContent() method returns the ChildKey component as per the activeIndex value.So Because the activeIndex default value initially set to 0, The initially getContent method returnselement = ChildKey name=’abc’ ChildKey component, we’ve initiallize the state i.e state = {childName: props.name} and when clicking on change parent component state link, then parent…
  • So name ‘bcd’ is printed and the element var becmes like below -element = ChildKey name=’bcd’ here we’re not using the key props, In ChildKey component.
  • Here react assuming both are same, So when constructor is call (constructor is called only one time in component life cycle), It initializes the state childName to ‘abc’ and In second time (when activeIndex changes to 1) constructor is not called, because react don’t know that It is separate component….
  • /ChildKey’;class ParentKey extends Component { constructor() { super(); this.state = {activeIndex: 0}; } updateIndex = () = { const {activeIndex} = this.state; this.setState({activeIndex: activeIndex + 1}) }getContent() { const {activeIndex} = this.state; let element; switch(activeIndex) { case 0: element = ChildKey name=’abc’ key=’23422%%%%’ updateData={this.updateIndex} / break; case 1: element =…

Most of the user had faced the problem of ‘key error’ i.e Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method of xyz component, while using the custom…
Continue reading “Key concept and Its necessities in React component – Shubham Akodiya – Medium”

#React Components – Zero To Hero Series – Part 2 by Vipul Jain cc @CsharpCorner #ReactJS

#React Components - Zero To Hero Series - Part 2 by Vipul Jain cc @CsharpCorner  #ReactJS

  • This is the second article in the ReactJS – Zero to Hero Series.
  • I recommend reading the first article (link given below), before going through this article.
  • In this article, we will see the explanation of React Components.
  • Components are the fundamental units of a React application.
  • Now, with this basic understanding, in the next articles, we will see more about Populating Props, Composing components, State, Default props and Validating props.

This is the second article in ReactJS – Zero to Hero Series. I will recommend you read the first article (link given below), before going through this article.
Continue reading “#React Components – Zero To Hero Series – Part 2 by Vipul Jain cc @CsharpCorner #ReactJS”

Array Methods Explained : Filter vs Map vs Reduce vs Foreach

  • we all know why this method is used for and even you don’t know about this method the name pretty much explains everything.Foreach takes a callback function and run that callback function on each element of array one by one.var sample = [1, 2, 3];// es5sample.forEach(function (elem, index){ console.log(elem + ‘ comes at ‘ + index);})// es6sample.forEach((elem, index) = `${elem} comes at ${index}`)/*output1 comes at 02 comes at 13 comes at 2*/For every element on the array we are calling a callback which gets element its index provided by foreach.Basically forEach works as a traditional for loop looping over the array and providing you array elements to do operations on them.okay!
  • If the value is true element remains in the resulting array but if the return value is false the element will be removed for the resulting array.var sample = [1, 2, 3] // yeah same array// es5var result = sample.filter(function(elem){ return elem !
  • As a ReactJS developer I use map a lot inside my application UI.Map like filter foreach takes a callback and run it against every element on the array but whats makes it unique is it generate a new array based on your existing array.Let’s understand map with an examplevar sample = [1, 2, 3] // i am never gonna change Boo!
  • Yeah// es5var mapped = sample.map(function(elem) { return elem * 10;})// es6let mapped = sample.map(elem = elem * 10)console.log(mapped);/* output */[10, 20, 30]Map ran through every element of the array, multiplied it to 10 and returned the element which will be going to store inside our resulting array.Like filter, map also returns an array.
  • ReduceAs the name already suggest reduce method of the array object is used to reduce the array to one single value.For example if you have to add all the elements of an array you can do something like this.var sample = [1, 2, 3] // here we meet again// es5var sum = sample.reduce(function(sum, elem){ return sum + elem;})// es6var sum = sample.reduce((sum, elem) = sum + elem)console.log(sum)reduce takes a callback ( like every function we talked about ).

Okay so yeah we know they are different they have different purpose and goals still we don’t bother to understand them. We use arrays. A lot of arrays. We use arrays to show search lists, items added…
Continue reading “Array Methods Explained : Filter vs Map vs Reduce vs Foreach”

Why you need keys for collections in React.

Why you need keys for collections in #ReactJS:  #Javascript

  • React will even give you a nice warning:

    The output DOM is then:

    This makes sense, because if you consider that the key is a unique identifier for a conceptual element, react doesn’t want to waste time rendering both.

  • This will render elements like:

    Now let’s suppose that we add a user to the front of the list:

    This will render elements like:

    After we add another user, React will go into reconciliation, where it will update the dom depending on the shape of the elements returned from the component’s render function.

  • Obviously, it’s simply to add one dom element to the beginning, and leave the previous to unchanged.
  • A good key uniquely identifies the content of the element.
  • Here are the two trees produced with the username as the key:

    React now understands that the elements with keys “bob” and “sue” have remained unchanged, and we’ve simply re-introduced a new element with key “joe”.

This post will explain the importance of keys in React and some edge cases to consider when choosing them.
Continue reading “Why you need keys for collections in React.”

How to Animate the Items of a React Native FlatList

  • Be sure to subscribe!Animating EntryTo easily demo our animation we’ll animated to insertion of the list item.
  • When a new item is added to the people array we’ll change the opacity of the row and, via transform, the scale and rotation.It’s important to note that inside the TouchableOpacity we’re using an Animated.View which allows us to modify that component using animated values.First we’ll create a new animated value and, when the component mounts, we’ll change that value from 0 to 1 using Animated.timing.Then we need to drive our UI from these values.
  • We can’t do that in componentWillUnmout because the component will be gone before any animations can run!If you test this out though you’ll see that it doesn’t actually do anything — the row just disappears the same as before.If you comment out the onRemove function you can see that the animation is happening.What we can do is call the onRemove function when the animation completes.
  • We’re now left with some subtle, yet slick, animations for each row item for whenever they’re added or removed.
  • It covers component design, Redux, Redux Saga, and more animations!Want more React Native videos?

I was recently asked about animating items in a React Native list — specifically animating the item when added and removed. That’s what we’ll cover today! To accomplish this we’ll use the FlatList…
Continue reading “How to Animate the Items of a React Native FlatList”