A simple emotion intepretor. I am often confused with the meanings and I keep going to emojipedia. Wanted to make something like for my use with different sets.
For following along, you can pick any set: travel, food, flags, symbols, activity and make your own version of it. Mine is emotion interpretor, yours could be flag interpretor, or food interpretor. Make it yours!
ex01: getting started with reactjs
challenge
know your way through ReactJS website
can you explain..
declarative
component based
learn once, write anywhere in your words?
understanding
The best place to get started with ReactJS is the website. The first exercise is thus to explore the docs, know where everything is. How to look into docs if you have any issues.
Know that React is more about understanding the flow than syntax. You can always refer to syntax, but the concept of how React works is more important.
Few tutorials teach you how to think in React and that's why you keep struggling, it's time to pay attention.
it should take a variable and show welcome <username>
ex06: console onClick
challenge
create a button, say 'Like`.
put a liked message in console when this button is clicked.
understanding
onClick is different than DOM method onclick
we don't need to addEventListener() in React
ex07 live exercise: add and console onClick
challenge
create a variable, likeCounter
on every time the Like button is clicked, increment the counter variable
understanding
if you're able to complete this, you have done the entire cycle: input --> processing --> output for this mini likeCounter app/component. Only thing is that you're showing output outside the React app, let's bring it in.
ex08: update counter in view
challenge
use useState to update the state in React
show the updated state in console
now, consume the updated state in the view
understanding
array destructuring in ES6 observed
you need to give an initial value too
useState is
ex09: explain render cycle
challenge
Explain to someone how React render cycle works. view --> event ---> state ---> render()
ex10: handle data from input element
challenge
use an input element and put an onChange event
console the value which user is typing
update the value using useState (even this is consuming in view only)
now consume this value in view
understanding
look at forms section of React doc if you don't remember the syntax.
remember how we used .value property of input elements in vanillJS class? this is the same thing
I personally like React more, and there are many more like me, because it uses plain JS concepts and has less syntax overhead keeping the overall API to bare minimum.
ex11: show meaning
challenge
input and output is done, processing is pure JavaScript
create object to put all emoji data at one place
get data based on key, show that data in view using useState
if (inputEmoji in emojiDictionary)
understanding
Data structure
Using the right data structure for needs would help in making access and update faster
that's the whole idea behind DSA, we'll explore more in levelOne
let's revise
The flow is still same like any other program we have written till now.
input User clicks on an element, or write in input
process In the event handler, you update the state
output In the view, you consume the state and thus show it to user
bonus (Optional)
Make any app you made previously using React. The leap year app, the palindrome app etc.
Only the input/output changes, the processing remains same.
HANDLING A LIST OF DATA
ex12: convert an object to array
challenge
take the object created and get an array of keys
understanding
built in functions are there in JS
what is being returned is an array of keys and not the values
ex13: put lists in React
challenge
show all emojis that we know
understanding
map() and index
callback in map
ex14: put a click handler on list item (input)
challenge
onClick for any item, it show which item was clicked from the list
syntax: onClick={() => emojiClickHandler(emoji)}
understanding
you have one clickHandler for every item in list, make it unique by passing the emoji to the function
ex15: set state (processing)
challenge
onClick get the inputEmoji from the list and set the state again for setMeaning
understanding
output of setMeaning ie meaning is already shown in the view. Thus, different actions can lead to same output in an app.
**assignments for markEight and markNine**
markEight - The emoji interpreter app we made during the lecture is the mark8 requirement.