Taro-docs.jd.com/taro/docs/r… Taro document react.docschina.org/docs/hooks- react… The react reactjs.bootcss.com/docs/hooks- hook document… Hook API documentation

Taro proprietary

import{usePageScroll,useReachBottom}from'@tarojs/taro'Hooks
Copy the code

Basic Hooks

import{useState,useEffect}from'react'
Copy the code

useReducer

An alternative to useState. It receives a Reducer of the form (state, action) => newState and returns the current state and its accompanying dispatch method. (If you’re familiar with Redux, you already know how it works.)

UseReducer can be more useful than useState in some situations, such as when the state logic is complex and contains multiple subvalues, or when the next state depends on the previous state. Also, using useReducer can optimize performance for components that trigger deep updates because you can pass dispatches to child components instead of callbacks.

UseCallback (fn, deps) is equivalent to useMemo(() => FN, deps).

useRef

const refContainer=useRef(initialValue)
Copy the code

UseRef returns a mutable ref object whose.current property is initialized as the passed parameter (initialValue). The ref object returned remains constant throughout the life of the component.

useContext

const value=useContext(MyContext)
Copy the code

Receives a context (the return value of taro.createcontext) and returns the current value of that context. The current context value is determined by the value rendered first in the upper component.

When the component’s upper layer is updated recently, the Hook triggers a rerender and uses the latest Context value passed to the MyContext Provider.

useDidShow

useDidShow(() = >{
console.log('componentDidShow')})Copy the code

UseDidShow is an Taro proprietary Hook, equivalent to the componentDidShow page lifecycle Hook

useDidHide

Equivalent to componentDidHide page lifecycle hooks

usePullDownRefresh

Taro proprietary Hook, equivalent to onPullDownRefresh page lifecycle Hook

useReachBottom

Taro’s proprietary Hook, equivalent to the onReachBottom page lifecycle Hook

usePageScroll

Taro proprietary Hook, equivalent to onPageScroll page lifecycle Hook

useResize

Taro proprietary Hook, equivalent to onResize page lifecycle Hook

useShareAppMessage

Taro starting from 3.0.3, enableShareAppMessage: true must be configured for the page when using this Hook

useShareAppMessage

Taro proprietary hooks, equivalent to onShareAppMessage page lifecycle hooks

useTabItemTap

Taro proprietary Hook, equivalent to onTabItemTap page lifecycle Hook

useAddToFavorites

Taro 3.0.3 supports only wechat mini programs. This interface is in Beta and is supported from Android 7.0.15. For now, it is only supported on Android platforms

useAddToFavorites

Taro proprietary hooks, equivalent to onAddToFavorites page lifecycle hooks

useShareTimeline

This interface is the Beta version. When it is only supported on the Android platform, enableShareTimeline must be configured for the page: True is equivalent to the onShareTimeline page lifecycle hook

useReady

Taro’s proprietary hooks are equivalent to the onReady lifecycle hooks of a page.