title: react-beautiful-dnd pull out the anonymous function from React Draggable component
body: <p>I need to pull out the anonymous function from Draggable into a callback function using the useCallback(..., []) hook supplying the dependencies provided, snapshot if possible.</p>
  <p>Upon investigation we have found that the 3rd party component Draggable is using an anonymous function that essentially recreates the function on the stack for each step in the list.  When this happens for a route with 500 steps the stack trace gets increased by 500 bringing us closer to a stack overflow.</p>
  <p>React has a virtual dom, and if the child component has not changed it will not re-render it. But anonymous functions make it re-render every time, but if the anonymous function is pushed down one more layer it won't see it as changed.</p>
  <p>Here is my implemented code.</p>
  <pre><code>const StepContainer = ({
      step,
      index,
      draggedDescription,
      isSelected,
      selectedTaskIdsCount
  }: Props) =&gt; {
      return (
          &lt;Box data-testid=&quot;stepContainer&quot; className={stepContainer}&gt;
              &lt;Box className={'hoverstyle'}&gt;
                  &lt;Draggable draggableId={step.key} index={index} key={step.key}&gt;
                      {(
                          provided: DraggableProvided,
                          snapshot: DraggableStateSnapshot
                      ) =&gt; (
                          &lt;div
                              data-testid=&quot;clickHandler&quot;
                              {...provided.draggableProps}
                              ref={provided.innerRef}
                              data-is-dragging={
                                  snapshot.isDragging &amp;&amp; !snapshot.isDropAnimating
                              }
                              className={snapshot.isDragging ? `${dragging}` : ''}
                          &gt;
                              {snapshot.isDragging ? (
                                  &lt;DraggedStepAsset
                                      draggedDescription={draggedDescription}
                                      stepCount={
                                          selectedTaskIdsCount &gt; 1
                                              ? selectedTaskIdsCount
                                              : 1
                                      }
                                  /&gt;
                              ) : (
                                  &lt;AccordionSteps
                                      isSelected={isSelected}
                                      provided={provided}
                                      step={step}
                                  /&gt;
                              )}
                          &lt;/div&gt;
                      )}
                  &lt;/Draggable&gt;
              &lt;/Box&gt;
          &lt;/Box&gt;
      );
  };
  </code></pre>
  <p>The idea is to pull out the anonymous function into a callback function using the useCallback(..., []) hook supplying the dependecies provided, snapshot if possible.  Then we can wrap the useCallback function with a useMemo() to ensure React memoizes it, this could potentially enable react to reuse the same function on the stack for every step-component instead of adding it for each step-component.  Making our code much more optimized.
  Please help me to resolve this issue.</p>