Convert custom html5 ghost drag image to react hookiframe onload fires when iframe is not readyTypeError dispatcher.useState is not a function when using React HooksNot able to navigate to other page in react nativegetSnapshotBeforeUpdate using react hooksreact Hooks useState ArrayReact Hooks setTimeout and clearTimeoutReact Hooks: updating multiple hook states atomicallyReusable Dropdown with React HooksReactJS Context, Ref & componentDidMount CyclusManipulate array with react hooks

Creating graph out of particles images

How to display a duet in lyrics?

In the movie Harry Potter and the Order or the Phoenix, why didn't Mr. Filch succeed to open the Room of Requirement if it's what he needed?

Does this Foo machine halt?

What is a "Genuine Geraldo interviewee"?

Is multiplication of real numbers uniquely defined as being distributive over addition?

As a 16 year old, how can I keep my money safe from my mother?

Pretty heat maps

Double blind peer review when paper cites author's GitHub repo for code

How to query data in backups?

Acceptable to cut steak before searing?

Why was CPU32 core created, and how is it different from 680x0 CPU cores?

Improving software when the author can see no need for improvement

A question about 'reptile and volatiles' to describe creatures

Why did the RAAF procure the F/A-18 despite being purpose-built for carriers?

Is it really ~648.69 km/s delta-v to "land" on the surface of the Sun?

Why are the inside diameters of some pipe larger than the stated size?

Does this smartphone photo show Mars just below the Sun?

Could one become a successful researcher by writing some really good papers while being outside academia?

Does a code snippet compile? Or does it gets compiled?

Infeasibility in mathematical optimization models

Are any jet engines used in combat aircraft water cooled?

Team goes to lunch frequently, I do intermittent fasting but still want to socialize

Why are there so many Doppler Effect formulas?



Convert custom html5 ghost drag image to react hook


iframe onload fires when iframe is not readyTypeError dispatcher.useState is not a function when using React HooksNot able to navigate to other page in react nativegetSnapshotBeforeUpdate using react hooksreact Hooks useState ArrayReact Hooks setTimeout and clearTimeoutReact Hooks: updating multiple hook states atomicallyReusable Dropdown with React HooksReactJS Context, Ref & componentDidMount CyclusManipulate array with react hooks






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Refer to code below. It creates a custom ghost image from the element being dragged by cloning it and hiding it underneath.



I wanted to do this the right way, i.e. use a custom react hook with useLayoutEffect to appendChild and removeChild but got stuck as setDataTransfer needs the event and also requires that the dom node is mounted.



Was going to post my useCustomDragImage hook attempt but decided to post the working function instead as it clearly demonstrates what I am trying to do.



 function handleDragStart(e) 

const x, y, width, height = e.target.getBoundingClientRect();
const clientX, clientY = e;

const crt = e.target.cloneNode(e.target);
crt.style.color = "white";
crt.style.height = `$heightpx`;
crt.style.width = `$widthpx`;
crt.style.position = "absolute";
crt.style.top = "0";
crt.style.left = "0";
crt.style.zIndex = "-1";
e.target.parentNode.appendChild(crt);
e.dataTransfer.setDragImage(crt, clientX - x, clientY - y);

setTimeout(() => crt.parentNode.removeChild(crt), 0);





Edit: (my hook attempt)



import useLayoutEffect, useRef from 'react'

export default function useGhost()

const ref = useRef();
const parentRef = useRef();

useLayoutEffect(() =>
const element = ref.current;
const parent = parentRef.current;
if (!element) return;
console.log(parent)
// parent.appendChild(element);
return () => parent.removeChild(element);
)


function fromDomNode(e)
const x, y, width, height = e.target.getBoundingClientRect();
const x: mx, y: my = e;
console.log(mx, my)
ref.current = e.target.cloneNode(e.target);
parentRef.current = e.target.parentNode;
console.log(parentRef.current)
console.log(ref.current)
const crt = ref.current;
// crt.style.backgroundColor = "red";
// crt.style.border = '1px dotted white';
crt.style.color = "white";
crt.style.height = `$heightpx`;
crt.style.width = `$widthpx`;
crt.style.position = "absolute";
crt.style.top = "0";
crt.style.left = "0";
crt.style.zIndex = "-1";
console.log(x, y, width, height)
parentRef.current.appendChild(crt); <---- Should go in useLayoutEffect() but can't setDragImage without mounting it first!
e.dataTransfer.setDragImage(crt, mx - x, my - y);

// setTimeout(function ()
// crt.parentNode.removeChild(crt);
// , 1000);



return fromDomNode;











share|improve this question
































    0















    Refer to code below. It creates a custom ghost image from the element being dragged by cloning it and hiding it underneath.



    I wanted to do this the right way, i.e. use a custom react hook with useLayoutEffect to appendChild and removeChild but got stuck as setDataTransfer needs the event and also requires that the dom node is mounted.



    Was going to post my useCustomDragImage hook attempt but decided to post the working function instead as it clearly demonstrates what I am trying to do.



     function handleDragStart(e) 

    const x, y, width, height = e.target.getBoundingClientRect();
    const clientX, clientY = e;

    const crt = e.target.cloneNode(e.target);
    crt.style.color = "white";
    crt.style.height = `$heightpx`;
    crt.style.width = `$widthpx`;
    crt.style.position = "absolute";
    crt.style.top = "0";
    crt.style.left = "0";
    crt.style.zIndex = "-1";
    e.target.parentNode.appendChild(crt);
    e.dataTransfer.setDragImage(crt, clientX - x, clientY - y);

    setTimeout(() => crt.parentNode.removeChild(crt), 0);





    Edit: (my hook attempt)



    import useLayoutEffect, useRef from 'react'

    export default function useGhost()

    const ref = useRef();
    const parentRef = useRef();

    useLayoutEffect(() =>
    const element = ref.current;
    const parent = parentRef.current;
    if (!element) return;
    console.log(parent)
    // parent.appendChild(element);
    return () => parent.removeChild(element);
    )


    function fromDomNode(e)
    const x, y, width, height = e.target.getBoundingClientRect();
    const x: mx, y: my = e;
    console.log(mx, my)
    ref.current = e.target.cloneNode(e.target);
    parentRef.current = e.target.parentNode;
    console.log(parentRef.current)
    console.log(ref.current)
    const crt = ref.current;
    // crt.style.backgroundColor = "red";
    // crt.style.border = '1px dotted white';
    crt.style.color = "white";
    crt.style.height = `$heightpx`;
    crt.style.width = `$widthpx`;
    crt.style.position = "absolute";
    crt.style.top = "0";
    crt.style.left = "0";
    crt.style.zIndex = "-1";
    console.log(x, y, width, height)
    parentRef.current.appendChild(crt); <---- Should go in useLayoutEffect() but can't setDragImage without mounting it first!
    e.dataTransfer.setDragImage(crt, mx - x, my - y);

    // setTimeout(function ()
    // crt.parentNode.removeChild(crt);
    // , 1000);



    return fromDomNode;











    share|improve this question




























      0












      0








      0








      Refer to code below. It creates a custom ghost image from the element being dragged by cloning it and hiding it underneath.



      I wanted to do this the right way, i.e. use a custom react hook with useLayoutEffect to appendChild and removeChild but got stuck as setDataTransfer needs the event and also requires that the dom node is mounted.



      Was going to post my useCustomDragImage hook attempt but decided to post the working function instead as it clearly demonstrates what I am trying to do.



       function handleDragStart(e) 

      const x, y, width, height = e.target.getBoundingClientRect();
      const clientX, clientY = e;

      const crt = e.target.cloneNode(e.target);
      crt.style.color = "white";
      crt.style.height = `$heightpx`;
      crt.style.width = `$widthpx`;
      crt.style.position = "absolute";
      crt.style.top = "0";
      crt.style.left = "0";
      crt.style.zIndex = "-1";
      e.target.parentNode.appendChild(crt);
      e.dataTransfer.setDragImage(crt, clientX - x, clientY - y);

      setTimeout(() => crt.parentNode.removeChild(crt), 0);





      Edit: (my hook attempt)



      import useLayoutEffect, useRef from 'react'

      export default function useGhost()

      const ref = useRef();
      const parentRef = useRef();

      useLayoutEffect(() =>
      const element = ref.current;
      const parent = parentRef.current;
      if (!element) return;
      console.log(parent)
      // parent.appendChild(element);
      return () => parent.removeChild(element);
      )


      function fromDomNode(e)
      const x, y, width, height = e.target.getBoundingClientRect();
      const x: mx, y: my = e;
      console.log(mx, my)
      ref.current = e.target.cloneNode(e.target);
      parentRef.current = e.target.parentNode;
      console.log(parentRef.current)
      console.log(ref.current)
      const crt = ref.current;
      // crt.style.backgroundColor = "red";
      // crt.style.border = '1px dotted white';
      crt.style.color = "white";
      crt.style.height = `$heightpx`;
      crt.style.width = `$widthpx`;
      crt.style.position = "absolute";
      crt.style.top = "0";
      crt.style.left = "0";
      crt.style.zIndex = "-1";
      console.log(x, y, width, height)
      parentRef.current.appendChild(crt); <---- Should go in useLayoutEffect() but can't setDragImage without mounting it first!
      e.dataTransfer.setDragImage(crt, mx - x, my - y);

      // setTimeout(function ()
      // crt.parentNode.removeChild(crt);
      // , 1000);



      return fromDomNode;











      share|improve this question
















      Refer to code below. It creates a custom ghost image from the element being dragged by cloning it and hiding it underneath.



      I wanted to do this the right way, i.e. use a custom react hook with useLayoutEffect to appendChild and removeChild but got stuck as setDataTransfer needs the event and also requires that the dom node is mounted.



      Was going to post my useCustomDragImage hook attempt but decided to post the working function instead as it clearly demonstrates what I am trying to do.



       function handleDragStart(e) 

      const x, y, width, height = e.target.getBoundingClientRect();
      const clientX, clientY = e;

      const crt = e.target.cloneNode(e.target);
      crt.style.color = "white";
      crt.style.height = `$heightpx`;
      crt.style.width = `$widthpx`;
      crt.style.position = "absolute";
      crt.style.top = "0";
      crt.style.left = "0";
      crt.style.zIndex = "-1";
      e.target.parentNode.appendChild(crt);
      e.dataTransfer.setDragImage(crt, clientX - x, clientY - y);

      setTimeout(() => crt.parentNode.removeChild(crt), 0);





      Edit: (my hook attempt)



      import useLayoutEffect, useRef from 'react'

      export default function useGhost()

      const ref = useRef();
      const parentRef = useRef();

      useLayoutEffect(() =>
      const element = ref.current;
      const parent = parentRef.current;
      if (!element) return;
      console.log(parent)
      // parent.appendChild(element);
      return () => parent.removeChild(element);
      )


      function fromDomNode(e)
      const x, y, width, height = e.target.getBoundingClientRect();
      const x: mx, y: my = e;
      console.log(mx, my)
      ref.current = e.target.cloneNode(e.target);
      parentRef.current = e.target.parentNode;
      console.log(parentRef.current)
      console.log(ref.current)
      const crt = ref.current;
      // crt.style.backgroundColor = "red";
      // crt.style.border = '1px dotted white';
      crt.style.color = "white";
      crt.style.height = `$heightpx`;
      crt.style.width = `$widthpx`;
      crt.style.position = "absolute";
      crt.style.top = "0";
      crt.style.left = "0";
      crt.style.zIndex = "-1";
      console.log(x, y, width, height)
      parentRef.current.appendChild(crt); <---- Should go in useLayoutEffect() but can't setDragImage without mounting it first!
      e.dataTransfer.setDragImage(crt, mx - x, my - y);

      // setTimeout(function ()
      // crt.parentNode.removeChild(crt);
      // , 1000);



      return fromDomNode;








      reactjs react-hooks html5-draggable






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 7:25







      myleftshoe

















      asked Mar 27 at 6:52









      myleftshoemyleftshoe

      131 silver badge4 bronze badges




      131 silver badge4 bronze badges

























          0






          active

          oldest

          votes










          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%2f55371369%2fconvert-custom-html5-ghost-drag-image-to-react-hook%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          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%2f55371369%2fconvert-custom-html5-ghost-drag-image-to-react-hook%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현