Couse 3 (5.6)
Couse 3 (5.6)
Couse 3 (5.6)
So the filtersubscriptions are not being used anywhere but I want to pass it to SubscriptionList
because this is my dumb component which doesn’t have any logic. This is only being used to create
template which means it is presentational component. And the App JS will be our controlled
component which is stateful component where there are multiple states for maintaining data, for
updating them and for doing filters and transformations. So this forms our stateful component. We
are getting the filtered data that we had just passed in the SubscriptionList. Now lets see in the
SubscriptionList. We have shifted all the responsibilities for now. Now we will have to import the
subscription here since we are going to use it here instead of the app. So here we will import the
subcscription from Subscription. Okay, I have to write ‘from’. We had skipped ‘from’. Now if we will
see here, we are getting some errors. This error says that, ‘Objects are not valid as a React child.’
Here we are sending it in the object format. This is a child. It’s the child of App JS. SubscriptionList.
And here something will be written as object which is not a valid syntax. We had shifted all the
responsibilities but there is something that we need to do in SubscriptionList dot JS. We cannot
handle it this way. So we will have to change the way. Our approach will change a bit. And we will
add some condition in the return itself. So first of all, if we write our condition in ‘if’- props dot
subscription dot length is equal to is equal to zero, then I will have to return ‘h3’ instead of ‘content’.
H3 with No data found’ and we will end h3 here. Else what I have to do? If this ‘if’ condition doesn’t
hold true then I’ll have to return something else which is our whole function. The map function we
have, all of it would be called. I’ll add this whole thing here. So now our return statement has
become condition based. Now I am returning my return statement correctly. If I have to return this,
then I am already checking and returning only h3. If I have to make a list then I check the condition
first and then returning the list. Now in this I want to make a little changes with the UI perspective.
I’ll make this ul return a list with some class ‘list’ and I’ll add this map function within it. The function
will end here. Our ul tag will end here. As you all know that format we write in is of JavaScript and
whatever code we are writing is being understood by JavaScript and not by JSX which is why we will
enclose it in curly brackets. In the return tag also, I am adding a class in the h3 tag just for styling
since I want the styling to be nice. ‘List_no_date’ , ok. I am defining some of my classes like this. The
ul will end here. Our starting and closing bracket to start and close in the correct sequence otherwise
there it will show an issue of syntax compile error. So ultimately we have removed the logic from
here too. We cannot use such logic because we cannot store content in a variable and use it in a
child component. We will have to make return, condition based. Ans since we had added some
classes here, we have to define them in .css as well. So first of all we will define .list . I have not put
much styling. You can change the style or the class name. I’ll take padding 0. And our .list_no_data
we will keep its colour black since our background is white. We will centre the text align and then we
will see how our styling is applied. ‘List_style’, and we have already used both these classes in .js .
Now we will run it and see if our function is running. OK, length of undefined SubscriptionList. One of
the lengths in the SubscriptionList is undefined. It is because the property that we have taken here is
subscriptions and not subscription. You see, doing naming convention carefully is very important.
These kind of mistakes can give us errors. Now you can see I have added some more styling. Now
our actual output is running successfully and its showing no data found where there is no data. I
have centred the text align with some styling. I have made the ul list’s list type and padding none.
Here we can change the styling. But you know here we have split this and the way it had become
more complex is now split up and nice and simple. And now we are just calling another component
in our main component where our template will be rendered. Along with the split up we have seen
another thing here that we return condition based statements only and not the already made
templates. So this a very important concept where we have to use conditions and if the conditions
are not forming in one component then we will split up and get the if condition for return checked.
So now my ultimate goal has been achieved with different approaches. We have seen four
approaches till now. First we saw how to work on iterations. Then we saw how to filter using
the .filter method. Then we cleared out how to handle conditions using ternary operator. And finally
we learned the significance of && operator and how we can split up the ternary operator. We also
saw how we created and maintained a variable named content and only used that variable here. And
finally we did the split up, created a component named Subscription that is responsible for rendering
the lists which is a dumb component and wrote a condition based statement after forming a
condition. These were the things relevant to conditions and iterations and we already discussed
many things and their alternatives. Then we will return the JSX based on the condition. Yes, we have
covered all the points of this. Now next topic is adding handlers and along with adding handlers we
will see in details what things can be improvised and how to enhance certain functionalities , in the
next video.