์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
return connectDragSource(connectDropTarget(
<div style={{ ...style, opacity }}>
{text}
</div>
));
๊ทธ๋ฌ๋ ๋ค์๊ณผ ๊ฐ์ ์ฐ๊ฒฐ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ์ฌ ์ ๋ฌํ๋ ์ฐธ์กฐ( styled-components
์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ innerRef ์ฌ์ฉ), ๋ค์๊ณผ ๊ฐ์ด ํ์ญ์์ค.
return (
<MyElement
innerRef={instance => connectDragSource(connectDropTarget(findDOMNode(instance)))}
style={{ ...style, opacity }}
>
{text}
</MyElement>
);
๋ด๋ถ ํธ์ถ๋ง ์๋ํฉ๋๋ค(์ด ๊ฒฝ์ฐ connectDropTarget
, ํ์ง๋ง connectDropTarget
์ connectDragSource
๋ฐ๊พธ๋ฉด connectDragSource
๋ง ์๋ํฉ๋๋ค).
๊ทธ๋๋ ์๋ํฉ๋๋ค.
return (
<MyElement
innerRef={instance => {
const domNode = findDOMNode(instance)
connectDragSource(domNode)
connectDropTarget(domNode)
}}
style={{ ...style, opacity }}
>
{text}
</MyElement>
);
์ด์ ๊ฐ ์๋์?
์ด ๋ฌธ์ ์ ๋ํ ์์์ด ์์ต๋๊น?
React DnD๊ฐ ๊ธฐ๋ณธ div ์์๋ฟ๋ง ์๋๋ผ Styled-Components(innerRef ํฌํจ)์ ํจ๊ป ์๋ํ๋ค๋ฉด ์ข์ ๊ฒ์ ๋๋ค.
์ปค๋ฅํฐ ํจ์๊ฐ ๋ณต์ ๋ ReactElement๋ฅผ ๋ฐํํด์ผ ํ๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ด ์ด๋ป๊ฒ ์ผ์ด๋๋์ง ๊ถ๊ธํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ ๋๋ง ์ปจํ ์คํธ์์ ์ ๋๋ก ์๋ํ๋ ๊ฒ์ด ์ด์ํฉ๋๋ค. ์ด๋ค ์ผ์ด ๋ฐ์ํด์ผ ํ๋์ง ์ค๋ช ์ ๋ฃ๊ณ ์ถ์ต๋๋ค. :-)
์ด ๋ฌธ์ ๋ ์ต๊ทผ ํ๋์ด ์์๊ธฐ ๋๋ฌธ์ ์๋์ผ๋ก ์ค๋๋ ๊ฒ์ผ๋ก ํ์๋์์ต๋๋ค. ๋ ์ด์ ํ๋์ด ์์ผ๋ฉด ํ์๋ฉ๋๋ค. ๊ทํ์ ๊ธฐ์ฌ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด ๋ฌธ์ ์ ๋ํ ์์์ด ์์ต๋๊น?