[英]Next.js with Typescript - how to access app.js props and staticProps in functional component
I want to know if it's possible for me to access props passed down from app.js to all Component Page using typescript and functional components.我想知道我是否可以使用 typescript 和功能组件访问从 app.js 传递到所有组件页面的道具。 Take a look at app.js and index.ts
看看 app.js 和 index.ts
app.js:应用程序.js:
function MyApp({ Component, pageProps, router }) {
const [message, setMessage] = useState(false)
return (
<Component setMessage={setMessage} key={router.route} {...pageProps} />
)
}
export default MyApp
Index.ts:索引.ts:
function Home({products}): InferGetStaticPropsType<typeof getStaticProps>) {
return (
<div>Home</div>
)
}
export function getStaticProps(){
const products = []
}
I would like to be able to access the setMessage function AND the products from getStaticProps in the index.ts page.我希望能够在 index.ts 页面中访问 setMessage function 和 getStaticProps 中的产品。 I might be doing things the wrong way, thank you for your advice.
我可能做错了,谢谢你的建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.