{"action":"created","issue":{"url":"https://api.github.com/repos/ant-design/ant-design-pro/issues/1357","repository_url":"https://api.github.com/repos/ant-design/ant-design-pro","labels_url":"https://api.github.com/repos/ant-design/ant-design-pro/issues/1357/labels{/name}","comments_url":"https://api.github.com/repos/ant-design/ant-design-pro/issues/1357/comments","events_url":"https://api.github.com/repos/ant-design/ant-design-pro/issues/1357/events","html_url":"https://github.com/ant-design/ant-design-pro/issues/1357","id":317046980,"number":1357,"title":"Authorized组件中PromiseRender组件源码分析遇到难点，求大神指导","user":{"login":"Joyeuxman","id":21262781,"avatar_url":"https://avatars2.githubusercontent.com/u/21262781?v=4","gravatar_id":"","url":"https://api.github.com/users/Joyeuxman","html_url":"https://github.com/Joyeuxman","followers_url":"https://api.github.com/users/Joyeuxman/followers","following_url":"https://api.github.com/users/Joyeuxman/following{/other_user}","gists_url":"https://api.github.com/users/Joyeuxman/gists{/gist_id}","starred_url":"https://api.github.com/users/Joyeuxman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Joyeuxman/subscriptions","organizations_url":"https://api.github.com/users/Joyeuxman/orgs","repos_url":"https://api.github.com/users/Joyeuxman/repos","events_url":"https://api.github.com/users/Joyeuxman/events{/privacy}","received_events_url":"https://api.github.com/users/Joyeuxman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-24T02:21:21Z","updated_at":"2018-04-24T02:59:17Z","closed_at":null,"author_association":"NONE","body":"//以下代码位于Authorized组件中PromiseRender文件中，  由于该PromiseRender组件render中根据起组件内部状态state中component的有无判断渲染Component还是div>Spin，而Component属性会在componentDidMount和componentWillReceiveProps生命周期中分别进行设置，处理如下：\r\n将正常渲染和异常渲染的内容都判断一下是否实例化，根据React.isValidElement来判断传递进来的渲染内容是否为React元素，若为React元素可以直接渲染，如果不是React元素，是React组件之类的，要将其放入函数中返回其组件。问题就在这个地方，为什么所传递进来的渲染内容是一个组件的话，为什么不能直接进行渲染，而是要将其放入一个函数中并返回呢？\r\n我不知道以上分析是否正确，哪位大神指导下，多谢！\r\n// Determine whether the incoming component has been instantiated\r\n  // AuthorizedRoute is already instantiated\r\n  // Authorized  render is already instantiated, children is no instantiated\r\n  // Secured is not instantiated\r\n  checkIsInstantiation = target => {\r\n    if (!React.isValidElement(target)) {\r\n      console.log(`${target}组件不是一个合法的React元素，即用React.createElement来创建的元素`)\r\n      return target;\r\n    }\r\n    return () => target;\r\n  };"},"comment":{"url":"https://api.github.com/repos/ant-design/ant-design-pro/issues/comments/383787776","html_url":"https://github.com/ant-design/ant-design-pro/issues/1357#issuecomment-383787776","issue_url":"https://api.github.com/repos/ant-design/ant-design-pro/issues/1357","id":383787776,"user":{"login":"Joyeuxman","id":21262781,"avatar_url":"https://avatars2.githubusercontent.com/u/21262781?v=4","gravatar_id":"","url":"https://api.github.com/users/Joyeuxman","html_url":"https://github.com/Joyeuxman","followers_url":"https://api.github.com/users/Joyeuxman/followers","following_url":"https://api.github.com/users/Joyeuxman/following{/other_user}","gists_url":"https://api.github.com/users/Joyeuxman/gists{/gist_id}","starred_url":"https://api.github.com/users/Joyeuxman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Joyeuxman/subscriptions","organizations_url":"https://api.github.com/users/Joyeuxman/orgs","repos_url":"https://api.github.com/users/Joyeuxman/repos","events_url":"https://api.github.com/users/Joyeuxman/events{/privacy}","received_events_url":"https://api.github.com/users/Joyeuxman/received_events","type":"User","site_admin":false},"created_at":"2018-04-24T02:59:17Z","updated_at":"2018-04-24T02:59:17Z","author_association":"NONE","body":"第一次提问题，忘记还有md语法，不好意思"}}
{"actor":{"display_login":"Joyeuxman"}}