Крюк не принять, чтобы получить ссылку из пользовательского компонента? - PullRequest
0 голосов
/ 24 октября 2019

Например, я хочу получить ссылку в компоненте сообщения: Main.js:

import * as React from "react"
export const Main: React.FunctionComponent<Props> = observer((props) => {
  const ref = React.useRef()

  React.useEffect(() => {
    ///Can not get ref from message
    ref.current.gotoPosition(5)
  }, [])
  return (
    <View style={styles.container}>
      <Message
        ref={ref}
        />
    </View>
  )
}

Message.js:

import * as React from "react"
// eslint-disable-next-line react/display-name
export const Message = React.forwardRef((props, ref) => ({
  const { ... } = props

  const gotoPosition = (index) => {
    console.log('in here')
  }
  return (
    <View>
....
</View>
  )
}
)

Я не могу получить ссылку из сообщения, дажея использовал React.forwardRef. Как получить доступ к функции gotoPosition в сообщении с помощью ref, как ref.gotoPosition (5). Спасибо

...