- I am spending some time to go back over the foundations of Reactjs. There are a couple of concepts that I was never truly clear about on the level of what's actually happening. This tutorial helped me before - application wise, but I'm doing it again for both application and listening out more for explainations to things.
To reinforce my learning of this lesson on props, hooks & state, I started on a simple React app that lists my favorite movies & tv shows. Nothing fancy, it's all in App.js
.
- I set an array of objects (movies/tv shows) to state using a React hook.
const [shows] = useState([ {name: "name" , etc. } ])
- I created additional logic as well --
- A dark mode hook:
- The state is set to
false
by default because I want the default theme to show first.
const [darkMode, setDarkMode] = useState(false);
- An onClick event:
- When triggered, this function is what causes dark mode to toggle
true
or false
based on the current condition.
This function {theme}
is setting darkMode to either true/false
.
const theme = () => {
setDarkMode(!darkMode);
};
When users click the button, it will trigger the above function: {theme}
.
<button
onClick={theme}
className={ darkMode ? "themechanger-button-dark" : "themechanger-button" }>
Change Theme
</button>
-
Any element that needs to be changed based on the toggle have a className
of {darkMode ? "class" : "class"}
- if darkMode
state is true
set class to appropriate class, if false
set to appropriate class.
-
The change theme button is located at the top of the page so users have ease of access to the toggle dark mode on/off.
I'll be continuing to work on this project next go round!
Updated: February 16, 2020
Updated: February 17, 2020
- Render a list of movies using Context API and display the number of movies on the list.
Updated: February 18, 2020
Updated: February 20, 2020
React Router, dynamic routing, fetch API:
Updated: February 26, 2020
- Created a recipe app using React with search functionality
yarn add 100-days-of-code
yarn start