A
A
Artur Kudashev2019-05-21 18:24:25
React
Artur Kudashev, 2019-05-21 18:24:25

How to wrap a component?

Hello, I made a clone of Trello on React and dnd on pure JS. I want to port dnd from JS to React, because when I drag an element into a list, it gets added to the list's children list in the DOM, but not added to the list's state, and there are a number of problems. Also I can't access list methods and its state from dnd. I have been learning React for a relatively short time, so I may not know some things. If I'm saying something wrong, please correct me. I think I need to make a board wrapper. Like this:

<DragManager>
    <Board />
<DragManager />

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2019-05-21
@archi_kud

Are you trying to use the methods of the wrapped component from the wrapper?) This won't work.
I think you should move the necessary methods to the parent component. Conditionally:

class Example extends React.Component {
  state: {
  }

  needMethod1{
  };

  needMethod2{
  }

  render() {
    return (
      <DragManager needMethod1={this.needMethod1} needMethod2={this.needMethod2} >
        <Board needMethod1={this.needMethod1} needMethod2={this.needMethod2} />
      <DragManager />
    )
  }
}

P.S. - and in order not to duplicate the code, you can read about HOC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question