react-dnd DragSource that has child DragSourceLoop inside React JSXReact js onClick can't pass value to methodWhat do these three dots in React do?Programmatically navigate using react routerWhen using React-DnD: How can I / should I even try to the access the state of a wrapped child component?React D3 Tree Chart Improper RerenderingWhat is the difference between React Native and React?assert react component child(ren) existence/absence using jestjsHow do you move a dragsource with React-DND?React - How do I give each child component a unique ref?

Is there a conventional notation or name for the slip angle?

Is it possible to have a strip of cold climate in the middle of a planet?

How do I implement a file system driver driver in Linux?

Some numbers are more equivalent than others

Indicating multiple different modes of speech (fantasy language or telepathy)

Transformation of random variables and joint distributions

Can someone explain how this makes sense electrically?

Did US corporations pay demonstrators in the German demonstrations against article 13?

Why did the EU agree to delay the Brexit deadline?

A Permanent Norse Presence in America

How will losing mobility of one hand affect my career as a programmer?

Greatest common substring

Is camera lens focus an exact point or a range?

Would it be legal for a US State to ban exports of a natural resource?

How do ground effect vehicles perform turns?

How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?

Folder comparison

What is the gram­mat­i­cal term for “‑ed” words like these?

Why has "pence" been used in this sentence, not "pences"?

Proof of Lemma: Every nonzero integer can be written as a product of primes

Is a model fitted to data or is data fitted to a model?

Can a significant change in incentives void an employment contract?

Could solar power be utilized and substitute coal in the 19th century?

Has Darkwing Duck ever met Scrooge McDuck?



react-dnd DragSource that has child DragSource


Loop inside React JSXReact js onClick can't pass value to methodWhat do these three dots in React do?Programmatically navigate using react routerWhen using React-DnD: How can I / should I even try to the access the state of a wrapped child component?React D3 Tree Chart Improper RerenderingWhat is the difference between React Native and React?assert react component child(ren) existence/absence using jestjsHow do you move a dragsource with React-DND?React - How do I give each child component a unique ref?













1















I have a tree structure with a root "Tree" component that has a list of root "TreeNodes", then TreeNodes can have an arbitrary number of children.



So inside of the TreeNode render method I have



 childrenHTML = this.state.children.map((child) => 
return (<TreeNode nodeClick =this.props.nodeClick parentNode=this
key=child.childId node=child level=this.state.level+1 />);
);


and



const isDragging, connectDragSource, connectDragPreview = this.props;



Then the final return for the render method looks like



return connectDragSource(
<div>
<div style=nodeStyle>
connectDragPreview(
<div className = "nodeContainer" + ' ' + this.state.nodeHover onMouseLeave=this.nodeUnHover onMouseOver=this.nodeHover onClick=()=>this.props.nodeClick(this)>
<img alt = this.state.titleIcon className = "titleIcon" src = Connections.getImageURLByName(this.state.titleIcon) />
<p className="nodeLabel"> this.state.nodeName</p>
nodeLabelsHTML
<DescriptiveIcons descriptiveIcons=this.state.icons />
</div>
)
</div>
childrenHTML
</div>
);


I am exporting:



export default DragSource(DragTypes.STRUCTURE, treeNodeSource, collect)(TreeNode);



Then in the parent Tree file I am exporting



export default DragDropContext(HTML5Backend)(Tree)



and rendering the rootnodes like



 rootNodesHTML = rootNodes.map((node) => 
return <TreeNode nodeClick=this.props.nodeClick key=node.childId node=node level=0/>
);


...



return (
<div className="treeContainer">
<div className="wrapContainer">
rootNodesHTML
</div>
</div>
);


This works great but only for the rootnodes, when I try to render the children (the childrenHTML variable is only populated after the parent is clicked on) I get the following error:TypeError: connectDragPreview is not a function



Leading me to believe that those react-dnd props that come from the "collect" function is not being passed to the rootnodes but not the children. It seems like it should to me because the same code should be executed for the parents as for the children as its the same class... really stuck here.



I am relatively new to react, and new to ideas like HOCs so all tips or suggestions are appreciated. Thank you!










share|improve this question


























    1















    I have a tree structure with a root "Tree" component that has a list of root "TreeNodes", then TreeNodes can have an arbitrary number of children.



    So inside of the TreeNode render method I have



     childrenHTML = this.state.children.map((child) => 
    return (<TreeNode nodeClick =this.props.nodeClick parentNode=this
    key=child.childId node=child level=this.state.level+1 />);
    );


    and



    const isDragging, connectDragSource, connectDragPreview = this.props;



    Then the final return for the render method looks like



    return connectDragSource(
    <div>
    <div style=nodeStyle>
    connectDragPreview(
    <div className = "nodeContainer" + ' ' + this.state.nodeHover onMouseLeave=this.nodeUnHover onMouseOver=this.nodeHover onClick=()=>this.props.nodeClick(this)>
    <img alt = this.state.titleIcon className = "titleIcon" src = Connections.getImageURLByName(this.state.titleIcon) />
    <p className="nodeLabel"> this.state.nodeName</p>
    nodeLabelsHTML
    <DescriptiveIcons descriptiveIcons=this.state.icons />
    </div>
    )
    </div>
    childrenHTML
    </div>
    );


    I am exporting:



    export default DragSource(DragTypes.STRUCTURE, treeNodeSource, collect)(TreeNode);



    Then in the parent Tree file I am exporting



    export default DragDropContext(HTML5Backend)(Tree)



    and rendering the rootnodes like



     rootNodesHTML = rootNodes.map((node) => 
    return <TreeNode nodeClick=this.props.nodeClick key=node.childId node=node level=0/>
    );


    ...



    return (
    <div className="treeContainer">
    <div className="wrapContainer">
    rootNodesHTML
    </div>
    </div>
    );


    This works great but only for the rootnodes, when I try to render the children (the childrenHTML variable is only populated after the parent is clicked on) I get the following error:TypeError: connectDragPreview is not a function



    Leading me to believe that those react-dnd props that come from the "collect" function is not being passed to the rootnodes but not the children. It seems like it should to me because the same code should be executed for the parents as for the children as its the same class... really stuck here.



    I am relatively new to react, and new to ideas like HOCs so all tips or suggestions are appreciated. Thank you!










    share|improve this question
























      1












      1








      1








      I have a tree structure with a root "Tree" component that has a list of root "TreeNodes", then TreeNodes can have an arbitrary number of children.



      So inside of the TreeNode render method I have



       childrenHTML = this.state.children.map((child) => 
      return (<TreeNode nodeClick =this.props.nodeClick parentNode=this
      key=child.childId node=child level=this.state.level+1 />);
      );


      and



      const isDragging, connectDragSource, connectDragPreview = this.props;



      Then the final return for the render method looks like



      return connectDragSource(
      <div>
      <div style=nodeStyle>
      connectDragPreview(
      <div className = "nodeContainer" + ' ' + this.state.nodeHover onMouseLeave=this.nodeUnHover onMouseOver=this.nodeHover onClick=()=>this.props.nodeClick(this)>
      <img alt = this.state.titleIcon className = "titleIcon" src = Connections.getImageURLByName(this.state.titleIcon) />
      <p className="nodeLabel"> this.state.nodeName</p>
      nodeLabelsHTML
      <DescriptiveIcons descriptiveIcons=this.state.icons />
      </div>
      )
      </div>
      childrenHTML
      </div>
      );


      I am exporting:



      export default DragSource(DragTypes.STRUCTURE, treeNodeSource, collect)(TreeNode);



      Then in the parent Tree file I am exporting



      export default DragDropContext(HTML5Backend)(Tree)



      and rendering the rootnodes like



       rootNodesHTML = rootNodes.map((node) => 
      return <TreeNode nodeClick=this.props.nodeClick key=node.childId node=node level=0/>
      );


      ...



      return (
      <div className="treeContainer">
      <div className="wrapContainer">
      rootNodesHTML
      </div>
      </div>
      );


      This works great but only for the rootnodes, when I try to render the children (the childrenHTML variable is only populated after the parent is clicked on) I get the following error:TypeError: connectDragPreview is not a function



      Leading me to believe that those react-dnd props that come from the "collect" function is not being passed to the rootnodes but not the children. It seems like it should to me because the same code should be executed for the parents as for the children as its the same class... really stuck here.



      I am relatively new to react, and new to ideas like HOCs so all tips or suggestions are appreciated. Thank you!










      share|improve this question














      I have a tree structure with a root "Tree" component that has a list of root "TreeNodes", then TreeNodes can have an arbitrary number of children.



      So inside of the TreeNode render method I have



       childrenHTML = this.state.children.map((child) => 
      return (<TreeNode nodeClick =this.props.nodeClick parentNode=this
      key=child.childId node=child level=this.state.level+1 />);
      );


      and



      const isDragging, connectDragSource, connectDragPreview = this.props;



      Then the final return for the render method looks like



      return connectDragSource(
      <div>
      <div style=nodeStyle>
      connectDragPreview(
      <div className = "nodeContainer" + ' ' + this.state.nodeHover onMouseLeave=this.nodeUnHover onMouseOver=this.nodeHover onClick=()=>this.props.nodeClick(this)>
      <img alt = this.state.titleIcon className = "titleIcon" src = Connections.getImageURLByName(this.state.titleIcon) />
      <p className="nodeLabel"> this.state.nodeName</p>
      nodeLabelsHTML
      <DescriptiveIcons descriptiveIcons=this.state.icons />
      </div>
      )
      </div>
      childrenHTML
      </div>
      );


      I am exporting:



      export default DragSource(DragTypes.STRUCTURE, treeNodeSource, collect)(TreeNode);



      Then in the parent Tree file I am exporting



      export default DragDropContext(HTML5Backend)(Tree)



      and rendering the rootnodes like



       rootNodesHTML = rootNodes.map((node) => 
      return <TreeNode nodeClick=this.props.nodeClick key=node.childId node=node level=0/>
      );


      ...



      return (
      <div className="treeContainer">
      <div className="wrapContainer">
      rootNodesHTML
      </div>
      </div>
      );


      This works great but only for the rootnodes, when I try to render the children (the childrenHTML variable is only populated after the parent is clicked on) I get the following error:TypeError: connectDragPreview is not a function



      Leading me to believe that those react-dnd props that come from the "collect" function is not being passed to the rootnodes but not the children. It seems like it should to me because the same code should be executed for the parents as for the children as its the same class... really stuck here.



      I am relatively new to react, and new to ideas like HOCs so all tips or suggestions are appreciated. Thank you!







      javascript reactjs react-dnd






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 7:09









      Dylan KiddDylan Kidd

      69212




      69212






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I was able to get this working. Check out the example posted at the end of the thread in
          https://github.com/react-dnd/react-dnd/issues/332.



          Ultimately the solution was to wrap the TreeNode in a "DragContainer" with a very simple render method



          render()
          const ...props = this.props;
          return <TreeNode ...props/>



          Then in the TreeNode render method, when rendering the child nodes render a DragContainer instead, passing in all the usual props.



           childrenHTML = this.state.children.map((child) => 
          return <DragNodeContainer modalFunctions = this.props.modalFunctions nodeClick =this.props.nodeClick parentNode=this key=child.childId node=child level=this.state.level+1 />;
          );


          I am still unsure as to the technical reason for this, however, the fix seems to work for other people and it works for me!






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058359%2freact-dnd-dragsource-that-has-child-dragsource%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I was able to get this working. Check out the example posted at the end of the thread in
            https://github.com/react-dnd/react-dnd/issues/332.



            Ultimately the solution was to wrap the TreeNode in a "DragContainer" with a very simple render method



            render()
            const ...props = this.props;
            return <TreeNode ...props/>



            Then in the TreeNode render method, when rendering the child nodes render a DragContainer instead, passing in all the usual props.



             childrenHTML = this.state.children.map((child) => 
            return <DragNodeContainer modalFunctions = this.props.modalFunctions nodeClick =this.props.nodeClick parentNode=this key=child.childId node=child level=this.state.level+1 />;
            );


            I am still unsure as to the technical reason for this, however, the fix seems to work for other people and it works for me!






            share|improve this answer



























              0














              I was able to get this working. Check out the example posted at the end of the thread in
              https://github.com/react-dnd/react-dnd/issues/332.



              Ultimately the solution was to wrap the TreeNode in a "DragContainer" with a very simple render method



              render()
              const ...props = this.props;
              return <TreeNode ...props/>



              Then in the TreeNode render method, when rendering the child nodes render a DragContainer instead, passing in all the usual props.



               childrenHTML = this.state.children.map((child) => 
              return <DragNodeContainer modalFunctions = this.props.modalFunctions nodeClick =this.props.nodeClick parentNode=this key=child.childId node=child level=this.state.level+1 />;
              );


              I am still unsure as to the technical reason for this, however, the fix seems to work for other people and it works for me!






              share|improve this answer

























                0












                0








                0







                I was able to get this working. Check out the example posted at the end of the thread in
                https://github.com/react-dnd/react-dnd/issues/332.



                Ultimately the solution was to wrap the TreeNode in a "DragContainer" with a very simple render method



                render()
                const ...props = this.props;
                return <TreeNode ...props/>



                Then in the TreeNode render method, when rendering the child nodes render a DragContainer instead, passing in all the usual props.



                 childrenHTML = this.state.children.map((child) => 
                return <DragNodeContainer modalFunctions = this.props.modalFunctions nodeClick =this.props.nodeClick parentNode=this key=child.childId node=child level=this.state.level+1 />;
                );


                I am still unsure as to the technical reason for this, however, the fix seems to work for other people and it works for me!






                share|improve this answer













                I was able to get this working. Check out the example posted at the end of the thread in
                https://github.com/react-dnd/react-dnd/issues/332.



                Ultimately the solution was to wrap the TreeNode in a "DragContainer" with a very simple render method



                render()
                const ...props = this.props;
                return <TreeNode ...props/>



                Then in the TreeNode render method, when rendering the child nodes render a DragContainer instead, passing in all the usual props.



                 childrenHTML = this.state.children.map((child) => 
                return <DragNodeContainer modalFunctions = this.props.modalFunctions nodeClick =this.props.nodeClick parentNode=this key=child.childId node=child level=this.state.level+1 />;
                );


                I am still unsure as to the technical reason for this, however, the fix seems to work for other people and it works for me!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 14 at 5:44









                Dylan KiddDylan Kidd

                69212




                69212





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058359%2freact-dnd-dragsource-that-has-child-dragsource%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived