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

Taro(v1.3.12): hooks里return null会被解析成 jsx #4073

Closed
lbb00 opened this issue Aug 5, 2019 · 5 comments
Closed

Taro(v1.3.12): hooks里return null会被解析成 jsx #4073

lbb00 opened this issue Aug 5, 2019 · 5 comments
Assignees

Comments

@lbb00
Copy link

lbb00 commented Aug 5, 2019

问题描述
RT

复现步骤

  const fetchHandler = useCallback(fetchDelegate => {
    async function fetch() {
      const res = await commonApi.getPageFrameworks()
      const arr: any[] = []
      const pageList = res.data.pagelist
      let num = 0
      await Promise.all(
        pageList.map(async item => {
          if (item.style == 'audio_list' || item.style == 'banner_list') {
            arr.push({
              title: item.content.title,
              count: item.content.count,
              id: item.content.id,
              style: item.style
            })

            try {
              num = num + 1
              const current = num
              const { data } = await topicApi.getTopicAudioList({
                topicId: item.content.id,
                pageToken: '',
                limit: 6
              })
              dispatch(actions.setAudioListsItem(current, data.audio_list))
            } catch (e) {
              return null
            }
          }
        })
      )
      setPageFrameworksData(arr)
      return arr
    }
    fetchDelegate(fetch)
  }, [])

报错信息

ReferenceError: React is not defined
    at _callee$ (http://127.0.0.1:8000/output/app.js?loadFileStamp=undefined:11278:66)
    at tryCatch (http://127.0.0.1:8000/output/app.js?loadFileStamp=undefined:1465:40)
    at Generator.invoke [as _invoke] (http://127.0.0.1:8000/output/app.js?loadFileStamp=undefined:1684:22)
    at Generator.prototype.(anonymous function) [as next] (http://127.0.0.1:8000/output/app.js?loadFileStamp=undefined:1513:21)
    at step (http://127.0.0.1:8000/output/app.js?loadFileStamp=undefined:11098:30)
    at http://127.0.0.1:8000/output/app.js?loadFileStamp=undefined:11105:13
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
@taro-bot
Copy link

taro-bot bot commented Aug 5, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@yuche
Copy link
Contributor

yuche commented Aug 5, 2019

你这个文件是不是带有 JSX

@lbb00
Copy link
Author

lbb00 commented Aug 5, 2019

是的啊

@lbb00
Copy link
Author

lbb00 commented Aug 5, 2019

这导致了一些问题,由于null会被解析成jsx,我只能改为undefined,但是改为undefined后,如果页面上有myState || '默认'这种,会导致页面UI不跟新。

我现在只能 const NULL = null,然后再用这个NULL

@lbb00 lbb00 changed the title Taro(v1.3.11): hooks里return null会被解析成 jsx Taro(v1.3.12): hooks里return null会被解析成 jsx Aug 5, 2019
@yuche yuche added the 编译器 label Aug 5, 2019
@taro-bot taro-bot bot assigned yuche Aug 5, 2019
@taro-bot
Copy link

taro-bot bot commented Aug 5, 2019

CC @yuche

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