See the issue and the test case with original fix in https://github.com/facebook/react/pull/14802.

We'll need to fix it properly, see https://github.com/facebook/react/pull/14802#issuecomment-463277621.
<p>
          Your name is: <span>Dominic</span>
        </p>
      </div>,
    );
    result = shallowRenderer.render(<SomeOtherComponent defaultName={'Dan'} />);
    expect(result).toEqual(
      <div>
        <p>
          Your name is: <span>Dan</span>
        </p>
      </div>,
    );
  });
  it('should work with with forwardRef + any hook', () => {
    const SomeComponent = React.forwardRef((props, ref) => {
      const randomNumberRef = React.useRef({number: Math.random()});
      return (
        <div ref={ref}>
          <p>The random number is: {randomNumberRef.current.number}</p>
        </div>
      );
    });
    const shallowRenderer = createRenderer();
    let firstResult = shallowRenderer.render(<SomeComponent />);
    let secondResult = shallowRenderer.render(<SomeComponent />);
    expect(firstResult).toEqual(secondResult);
  });
});