How do you add refs to functional components using withHandlers in Recompose and call ScrollTo on a ScrollView?

后端 未结 3 874
囚心锁ツ
囚心锁ツ 2021-02-13 21:12

My specific goal is to use the ScrollTo method of a ScrollView but maintain functional component structure.

More generally this requires getting ref to the current compo

3条回答
  •  死守一世寂寞
    2021-02-13 22:14

    Another way is to make a class as a ref store:

    const Stateless = ({ refs }) => (
      
    refs.store('myFoo', r)} />
    refs.myFoo.doSomeStuff()}> doSomeStuff
    ) class RefsStore { store(name, value) { this[name] = value; } } const enhancer = compose( withProps({ refs: new RefsStore() }), )(Stateless);

提交回复
热议问题