D
D
darktowerk56c2020-02-22 13:15:30
React
darktowerk56c, 2020-02-22 13:15:30

How to get references in React.js?

Hello. Guys, tell me, please, how can I get links to the nodes (references) of the contents of the TabPanel in the Tab component, when it is initialized?
https://codepen.io/darktowerk56c/pen/NWqbXmK
I tried to do this solution, but it is obviously not correct:

const Tabs = ({children}) => {

  const node = useRef(null)

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

  return (
    <div className="tabs">
      {
        React.Children.map(children, (child, idx) => {
          console.log('child', child)
          const cloneElement = React.cloneElement(child, {
            ref: {node}
          })
          return cloneElement
        })
      }
    </div>
  );
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question