Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ In this project you'll take this crypto currency tracker app and build two custo

## Project Set Up

- [ ] Create a forked copy of this project.
- [ ] Clone your OWN version of the repository in your terminal
- [ ] CD into the project base directory `cd dark-mode`
- [ ] Download project dependencies by running `npm install`
- [ ] Start up the app using `npm start`
- [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
- [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
- [ ] Push commits: git push origin `<firstName-lastName>`.
- [x] Create a forked copy of this project.
- [x] Clone your OWN version of the repository in your terminal
- [x] CD into the project base directory `cd dark-mode`
- [x] Download project dependencies by running `npm install`
- [x] Start up the app using `npm start`
- [x] Create a new branch: git checkout -b `<firstName-lastName>`.
- [x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
- [x] Push commits: git push origin `<firstName-lastName>`.

Follow these steps for completing your project.

- [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into main (student's Repository). **Please don't merge your own pull request**
- [ ] From the home page of your repo, make sure you have your branch selected
- [ ] Copy the URL and paste it into Canvas

## Minimum Viable Product

- [ ] Build a custom hook that let's you save data to localStorage
Expand Down Expand Up @@ -84,7 +84,7 @@ export const useLocalStorage = (key, initialValue) => {
- `setValue` should look something like this:

```js
const setValue = value => {
const setValue = (value) => {
// Save state
setStoredValue(value);
// Save to local storage
Expand Down
2 changes: 1 addition & 1 deletion src/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React from 'react'; // removed { useState } to clear the following warning in console: Line 1:17: 'useState' is defined but never used no-unused-vars

const Navbar = (props) => {
const toggleMode = e => {
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useDarkMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useLocalStorage } from "./useLocalStorage";

export const useDarkMode = (initialValue) => {
const [darkMode, setDarkMode] = useLocalStorage(useDarkMode, initialValue);
return [darkMode, setDarkMode];
}
17 changes: 17 additions & 0 deletions src/hooks/useLocalStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useState } from "react";

export const useLocalStorage = (key, initialValue) => {
const [storedValue, setStoredValue] = useState(() => {
const item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
})
// setValue function
const setValue = value => {
//Save state
setStoredValue(value);
//Save to local storages
window.localStorage.setItem(key, JSON.stringify(value));
};
//returning an array
return [storedValue, setValue];
}
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import axios from "axios";

import Charts from "./components/Charts";
import Navbar from "./components/Navbar";

import { useDarkMode } from "./hooks/useDarkMode";

import "./styles.scss";

const App = () => {
const [coinData, setCoinData] = useState([]);
const [darkMode, setDarkMode] = useState(false);
const [darkMode, setDarkMode] = useDarkMode(false); // change useState to the useDarkMode hook

useEffect(() => {
axios
Expand Down
12 changes: 6 additions & 6 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ blockquote:before,
blockquote:after,
q:before,
q:after {
content: '';
content: "";
content: none;
}
table {
Expand All @@ -136,7 +136,7 @@ table {

html {
font-size: 62.5%;
font-family: 'Open Sans', sans-serif;
font-family: "Open Sans", sans-serif;
font-weight: 500;
}

Expand Down Expand Up @@ -229,8 +229,8 @@ img {
.coin__title {
display: block;
margin-left: 8px;
min-width: 160px;
text-align: left;
min-width: 160px;
text-align: left;
}

.coin__symbol {
Expand All @@ -243,11 +243,11 @@ text-align: left;
}

.dark-mode {
color: #fff;
color: #8dc648;
background-color: #313843;

.navbar {
background-color: #1F2022;
background-color: #1f2022;
border: none;
}
}