Access request/context inside App component using pages directory
Answered
Swedish Elkhound posted this in #help-forum
Swedish ElkhoundOP
Hello, how can one access the request or context from the App component in a pages dir project? We need to read/set cookied from this component.
Answered by joulev
[use
getInitialProps with _app](https://nextjs.org/docs/pages/building-your-application/routing/custom-app#getinitialprops-with-app) is the only way to do it, though it's not recommended for reasons explained in the link. to read/set cookies you should probably use [middleware](https://nextjs.org/docs/pages/building-your-application/routing/middleware) instead2 Replies
@Swedish Elkhound Hello, how can one access the request or context from the App component in a pages dir project? We need to read/set cookied from this component.
[use
getInitialProps with _app](https://nextjs.org/docs/pages/building-your-application/routing/custom-app#getinitialprops-with-app) is the only way to do it, though it's not recommended for reasons explained in the link. to read/set cookies you should probably use [middleware](https://nextjs.org/docs/pages/building-your-application/routing/middleware) insteadAnswer
Swedish ElkhoundOP
Got it, makes sense, thanks!!