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
16 changes: 9 additions & 7 deletions src/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const UserContext = createContext([
suffix: 1,
email: "bobbobberson@example.com"
},
(obj) => obj
(obj) => obj //the reason putting this is to make typed with typescript easier
]);

const LevelFive = () => {
Expand Down Expand Up @@ -49,13 +49,15 @@ const LevelTwo = () => (
);

const ContextComponent = () => {
const userState = useState({
firstName: "James",
lastName: "Jameson",
suffix: 1,
email: "jamesjameson@example.com"
});
// const userState = useState({
// firstName: "James",
// lastName: "Jameson",
// suffix: 1,
// email: "jamesjameson@example.com"
// });

const userState = useContext(UserContext);
//take with hook
return (
<UserContext.Provider value={userState}>
<h1>first level</h1>
Expand Down
12 changes: 11 additions & 1 deletion src/Effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ const EffectComponent = () => {

useEffect(() => {
const timer = setTimeout(() => setTime(new Date()), 1000);
return () => clearTimeout(timer);
return () => clearTimeout(timer); //same idea with component didunmount
});

async function getPets() {
const obj = await fetch("https://pets-v2.dev-apis.com/pets");
const json = await obj.json();
console.log(json);
}

useEffect(() => {
getPets();
}, []);

return <h1>useEffect Example: {time.toLocaleTimeString()}</h1>;
};

Expand Down
6 changes: 5 additions & 1 deletion src/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const StateComponent = () => {
return (
<h1
onClick={() => setIsGreen(!isGreen)}
style={{ color: isGreen ? "limegreen" : "crimson" }}
style={{
color: isGreen ? "limegreen" : "crimson",
cursor: "pointer",
userSelect: "none"
}}
>
useState Example
</h1>
Expand Down