0

Outline We're trying to divide up a large React.js project into several node packages which can be seperately maintained. We are trying to extract all the complex three.js framework code and centralize it in a "previewer" package.

Problem We have a special case in which we need to use the ref keyword once in a component. I know it's bad practice :( , we were wondering if there's anyway to remove or suppress the warning below from react:

Refs Must Have Owner Warning

Ben Winding
  • 10,208
  • 4
  • 80
  • 67
  • You should post your code, so people can see why you're getting the warning. You shouldn't get warnings *just* for using refs, they're a supported feature of React (albeit one you're supposed to avoid). – Joe Clay Aug 04 '17 at 08:21
  • @JoeClay we're dividing the react application into multiple npm modules. The main app refers to component npm modules, which contain these refs. The component npm modules are transpiled using babel, to be used by the main app. Will try and put some code up soon – Ben Winding Aug 05 '17 at 05:36

1 Answers1

0

Similar solution, that helped me

For anyone else having a similar issue, it turned out that multiple copies of React were being referenced, when having separate npm modules.

Here's my directory structure, the two npm modules react-app and react-mycomponent. During local development I was using npm link, to use the local version of the module. This unfortunately also uses the local versions "node_modules"

  • react-app/
    • node_modules/
  • react-mycomponent/
    • node_modules/

this means all import statements import React from 'react'; were importing from the react-mycomponent/node_modules folder.

In order to prevent this, I changed all references:

import React from 'react';

to

var React = require('react');

Ben Winding
  • 10,208
  • 4
  • 80
  • 67