在 React 中,什么调用了诸如高阶组件和 redux-thunk 之类的返回函数?



我的问题是关于什么调用了 React 中返回的函数? 例如,使用 redux-thunk,假设我从任意组件的 componentDidMount(( 调用以下函数,

getCurrentPoll() 

我的 redux-thunk 操作定义如下:

export const getCurrentPoll = pollId => async dispatch => {
try {
const currentPoll = await api.call('get', `polls/${pollId}`)
dispatch(actionGetCurrentPoll(currentPoll))
dispatch(removeError())
} catch (err) {
const { message } = err.response.data
dispatch(addError(message))
}
}

我的理解是调用getCurrentPoll()将返回异步调度函数。 但是什么调用了返回的异步调度函数?

也适用于高阶组件。比如说下面的函数,它将上下文 API 值注入组件 props。

const withRoomConsumer = Component => props =>
<RoomContext.Consumer>
{value => <Component {...props} context={value} />}
</RoomContext.Consumer>

当你运行export default withRoomConsumer(RoomsContainer)时,什么调用返回的函数props =>...

提前谢谢你

>redux-thunk创建一个redux中间件,并检查该操作是否是一个函数,然后调用该函数。你可以在这里检查它们的实现,很简单,只有14行

ReactHOC 返回一个功能性 React 组件,React 将照常渲染该组件。(它也可以是类组件(

最新更新