when i imported postDetails in another component it says postDetails is undefined
import {createContext, useState} from 'react'
export const PostContext = createContext(null)
function Post({children}){
const [postDetails, setPostDetails] = useState('')
return(
<PostContext.Provider value={ postDetails , setPostDetails } >
{children}
</PostContext.Provider>
)
}
export default Post
CodePudding user response:
Value accepts an object (particularly one thing, same as all other props), wrap your value in an object. see value on PostContext.Provider
line:
return(
<PostContext.Provider value={{ postDetails , setPostDetails }} >
{children}
</PostContext.Provider>
)