-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { createContext, useEffect, useState } from 'react' | ||
import Feedback from '../data/FeedData' | ||
|
||
const FeedContext = createContext() | ||
|
||
export const FeedProvider = ({children}) => { | ||
const [feed, setFeed] = useState(Feedback) | ||
useEffect(() => { | ||
|
||
}, []) | ||
|
||
const deleteFeed = (id) => { | ||
setFeed(feed.filter(f => f.id != id)) | ||
} | ||
|
||
const addFeed = (newFeed) => { | ||
setFeed([newFeed, ...feed]) | ||
} | ||
|
||
const editFeed = () => { | ||
|
||
} | ||
|
||
return ( | ||
<FeedContext.Provider | ||
value={{ | ||
feed, | ||
addFeed, | ||
deleteFeed | ||
}} | ||
> | ||
{children} | ||
</FeedContext.Provider> | ||
) | ||
} | ||
|
||
export default FeedContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import Feedback from '../data/FeedData' | ||
import React, { useContext, useEffect, useState } from 'react' | ||
import { FeedList } from '../components/feed/FeedList' | ||
import { FeedStats } from '../components/feed/FeedStats' | ||
import { FeedForm } from '../components/feed/FeedForm' | ||
import FeedContext from '../context/FeedContext' | ||
|
||
export const Home = () => { | ||
const [feed, setFeed] = useState(Feedback) | ||
|
||
const deleteFeed = (id) => { | ||
setFeed(feed.filter(f => f.id != id)) | ||
} | ||
|
||
const addFeed = (newFeed) => { | ||
setFeed([newFeed, ...feed]) | ||
} | ||
|
||
const { feed } = useContext(FeedContext) | ||
return ( | ||
<div className="container"> | ||
<FeedForm addFeed = {addFeed} /> | ||
<FeedForm /> | ||
<FeedStats feed={feed} /> | ||
<FeedList feed={feed} deleteFeed={deleteFeed} /> | ||
<FeedList feed={feed} /> | ||
</div> | ||
) | ||
} |