Skip to content

Commit

Permalink
Merge pull request #6 from shubhamgautam89/shubhamgautam89-patch-1
Browse files Browse the repository at this point in the history
Shubhamgautam89 patch 1
  • Loading branch information
shubhamgautam89 authored Oct 12, 2023
2 parents 003873a + 65662e0 commit 26dacc4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions patterns/container-presentational/cp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Ideally, we want to enforce separation of concerns by separating this process into two parts:
* Presentational Components: Components that care about how data is shown to the user. In this example, that's the rendering the list of dog images.
* Container Components: Components that care about what data is shown to the user. In this example, that's fetching the dog images.
* In many cases the container component can be replaced wiith Hooks, for this example we wil be using hook as container.
*/

import { useState } from "react";

export default function useDogImages() {
const [dogs, setDogs] = useState([]);

useEffect(() => {
fetch("https://dog.ceo/api/breed/labrador/images/random/6")
.then((res) => res.json())
.then(({ message }) => setDogs(message));
}, []);

return dogs;
}

export function DogImages() {
const dogs = useDogImages();

return dogs.map((dog) => <img src={dog} key={i} alt="Dog" />);
}
Empty file added patterns/contribution.md
Empty file.

0 comments on commit 26dacc4

Please sign in to comment.