I am trying to use the state of users to display them in the posts page, but it does not render anything, I get an error "render is not a function". Any help is highly appreciated. This is my front end
This is my code:
function PostsList(props) {
let { deletePosts } = useContext(PostsContext);
let users = useContext(UserContext);
let formatDate=(input)=>{
let v=new Date(input);
return v.toLocaleDateString("en-US")
}
return (
<PostsContext.Consumer value={users}>
<UserContext.Consumer>
{
({ posts }) => {
return <div>
<h3>welcome back, {users.name}</h3>
<a href="/posts/new"><button>Add New Post</button></a>
<div>
{posts.map((c) => {
console.log(posts)
return (
<div className='posts_list'>
<div key={c._id}>
</div>
<div className='posts_text'>
<h2>{c.name}</h2>
</div>
<div className='list'>
<Link to={`/edit/${c._id}`}>
<button>Edit</button>
</Link>
<button onClick={() => { deletePosts(c._id)}}>Delete</button>
<p>Tweet created on: {formatDate(c.createdAt)}</p>
</div>
</div>
)
})}
</div>
</div>
}
}
</UserContext.Consumer>
</PostsContext.Consumer>
);
}
export default PostsList;
.Consumerwould not have avalue.