Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

按README文档使用,Add Inspector React Component部分似乎有点问题 #139

Closed
KeyToLove opened this issue Dec 15, 2022 · 4 comments

Comments

@KeyToLove
Copy link

README中创建 Add Inspector React Component 这一步按照示例会报错

import React from 'react'
import { Inspector, InspectParams } from 'react-dev-inspector'

const isDev = process.env.NODE_ENV === 'development'

export const Layout = () => {
  // ...

  return (
    <>
      <YourComponent />

      {isDev && (
        <Inspector
          // props see docs:
          // https://github.com/zthxxx/react-dev-inspector#inspector-component-props
          keys={['control', 'shift', 'command', 'c']}
          onHoverElement={(inspect: InspectParams) => {}}
          onClickElement={(inspect: InspectParams) => {}}
        >
      )}
    </>
  )
}

image

通过以下方式使用时正常的

const WrapperComponent =
  process.env.NODE_ENV === 'development' ? Inspector : Fragment

function App() {
  return (
    <div className="App">
      <WrapperComponent keys={["control", "shift", "alt", "f"]}>
         <YourComponent />
      </WrapperComponent>
    </div>
  )
}

这块是文档上的错误,还是我的使用方式哪里错了呢 :(

@SyMind
Copy link
Contributor

SyMind commented Feb 2, 2023

@KeyToLove 这是 bug,Inspector 的 children 为 undefined 导致的,目前你可以通过在 组件下添加一个空 React 组件解决这个问题:

<Inspector>
+    <></>
</Inspector>

@SyMind
Copy link
Contributor

SyMind commented Feb 2, 2023

@zthxxx 我看到代码中已经解决了这个问题,但最新的 npm 中并没有同步最新的代码。

https://github.com/zthxxx/react-dev-inspector/blob/master/src/Inspector/Inspector.tsx#L156

@KeyToLove
Copy link
Author

Thanks~ 这个 issue 我认为可以暂时留着,遇到相同问题的可以进行参照来使用,待文档或 npm 包更新再关闭。

@zthxxx
Copy link
Owner

zthxxx commented Jul 6, 2023

是的,代码早就更新了,只是 v1.6.8 终于想起来发版了 🌝

@zthxxx zthxxx closed this as completed Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants