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 3 React中Taro自带的hooks在app.js中没有触发 #8348

Closed
bokuns opened this issue Dec 22, 2020 · 3 comments · Fixed by #8430
Closed

Taro 3 React中Taro自带的hooks在app.js中没有触发 #8348

bokuns opened this issue Dec 22, 2020 · 3 comments · Fixed by #8430
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Milestone

Comments

@bokuns
Copy link

bokuns commented Dec 22, 2020

相关平台

微信小程序

小程序基础库: 2.14.1
使用框架: React

复现步骤

// 用class写app.js可以使用生命周期:

class App extends React.component {

    componentDidMount() {
	console.log('app mounted')
}

componentDidShow() {
	console.log('app showed')
}

render() {

	return (
		<Provider store={store}>
			{this.props.children}
		</Provider>
	)
}

}

// >> app mounted

// >> app showed

// 用函数写法,使用Taro的hooks无效:

const App = props => {

useEffect(() => {
    console.log('app mounted')
}, [])

useDidShow(() => {
    console.log('app showed')
})

return (
    <Provider store={store}>
    {this.props.children}
</Provider>
)

}

// >> app mounted

// 期望结果是可以打印出 app showed

期望结果

在app.js里面用class写的话componentDidShow是没问题的,换成函数形式写用useDidShow就没有触发。但是在pages里面的页面用useDidShow都是没问题的,想问一下这个是Taro本身的问题还是哪里没写对?

实际结果

在app.js中正常使用Taro的hooks (useDidShow, useDidHide等)

环境信息

Taro CLI 3.0.18 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 14.15.0 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.10 - C:\Users\XXX\AppData\Roaming\npm\yarn.CMD
      npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Dec 22, 2020
@Thinking80s
Copy link

遇到了同样的问题,函数组件没有触发执行

@xiashulin
Copy link

我也出现了,3.1.5版本

@Grace-xhw
Copy link

3.5.6 再次复现,app.tsx里面 useDidShow 不生效,pages里面的可以 @Chen-jj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants