Reactjs 我可以在getInitialProps/getServerSideProps/getStaticProps中包装React上下文API吗
如何使用NextJs的getInitialProps/getServerSideProps/getStaticProps中的React上下文API调用动作创建者 使用NextJs的redux,我可以访问Reactjs 我可以在getInitialProps/getServerSideProps/getStaticProps中包装React上下文API吗,reactjs,next.js,Reactjs,Next.js,如何使用NextJs的getInitialProps/getServerSideProps/getStaticProps中的React上下文API调用动作创建者 使用NextJs的redux,我可以访问存储,然后发送一个动作创建者。但是,对于React上下文API,我不知道如何做到这一点 Redux示例: Search.getInitialProps = async ({ store }) => { store.dispatch(fetch('next-js')); }); 如何使
存储
,然后发送一个动作创建者。但是,对于React上下文API,我不知道如何做到这一点
Redux示例:
Search.getInitialProps = async ({ store }) => {
store.dispatch(fetch('next-js'));
});
如何使用React上下文API实现这一点
谢谢你 在上下文提供程序中,您可以执行以下操作
export async function getStaticProps() {
// Call an external API endpoint to get posts.
// You can use any data fetching library
const res = await fetch("https://www.mocky.io/")
const search = await res.json()
// By returning { props: search }, the Search component
// will receive `search` as a prop at build time
return {
props: {
search,
},
}
}