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

用变量的方式传React.Node会让react报错 #22

Closed
winguse opened this issue May 18, 2016 · 7 comments
Closed

用变量的方式传React.Node会让react报错 #22

winguse opened this issue May 18, 2016 · 7 comments

Comments

@winguse
Copy link

winguse commented May 18, 2016

_renderALert () {
    const message = (
      <div>
        <p>test</p>
      </div>
    )
    return <Alert message={message} type='info' />
}
invariant.js:38 Uncaught (in promise) Error: Objects are not valid as a React child (found: object with keys {info, success, error, warn, warning, loading, config, destroy}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `Alert`

但是如果写成inline的是没问题的。。

@sorrycc
Copy link
Member

sorrycc commented May 18, 2016

这个和 babel-plugin-antd 有关?

@winguse
Copy link
Author

winguse commented May 18, 2016

我也不造为啥,就这么神奇。。。去掉插件这个它就听话了。

@winguse
Copy link
Author

winguse commented May 18, 2016

Promise 是因为我的render在一个promise之后,忽略它。。

@sorrycc
Copy link
Member

sorrycc commented May 18, 2016

没理解到出错的点在哪里,Alert 是从 antd 里 import 的? 还是因为定义了 message ? 给一个能重现的完整文件代码吧。

@winguse
Copy link
Author

winguse commented May 19, 2016

我找到原因了:

import React from 'react';
import { Alert, message } from 'antd';

export default class App extends React.Component {
  render() {
    const message = (<div><p>Test</p><p>Test</p></div>);
    return <Alert message={message} />;
  }
}

注意我的局部变量messageimport { Alert, message } from 'antd';里面的message重名了,应该是局部变量在babel编译时出问题了。

@sorrycc
Copy link
Member

sorrycc commented May 19, 2016

这种情况很难处理,换个名字吧。

@winguse
Copy link
Author

winguse commented May 19, 2016

walk around是可以得,不过应该有个更优雅的办法。。

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

2 participants