【问题标题】:next.js, styled-components, react-helmet. How to use all togethernext.js,样式化组件,反应头盔。如何一起使用
【发布时间】:2019-02-25 12:36:38
【问题描述】:

我遇到了一个问题,我无法将react-helmetstyled-componentnext.js 一起使用。

在 next.js 提供的示例中,他们在不同的 repos 中使用每个包。任何人都可以解决这个问题吗?

【问题讨论】:

  • 请在帖子中包含您的代码。否则,人们很难提供帮助。

标签: reactjs styled-components next.js react-helmet


【解决方案1】:

对于react-helmet,您可以使用现有的nextJS 库next/head

对于styled-component,我不确定您的情况,但有一个使用styled-component here 的nextJS 示例。

【讨论】:

  • 你不能用那个修改<html>
  • 你想达到什么目的? react-helmet 和 styled-component 都没有任何修改 标签的目的。
  • 您可能有时想为 标签动态设置 lang 属性...而这对于 next/head 是不可能的。但是 react-helmet 可以很方便,
  • 您可以使用_document.js 文件修改 标签中的语言。在此处阅读更多信息nextjs.org/docs/advanced-features/custom-document,它是您所有页面的包装器。不需要在你的 nextjs 应用上安装 react-helmet。
  • 我说的是应用程序使用例如 apollo 服务器/客户端的情况,因此执行的任何查询将主要在更深的组件中执行,例如当前页面的元数据获取,因此您无法使其工作_document.
猜你喜欢
  • 1970-01-01
  • 2021-10-10
  • 2017-12-03
  • 2020-10-27
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 2019-04-08
相关资源
最近更新 更多