Hi, guys!
First of all, thanks for your amazing work with code-push, it's awesome! 馃槈
After finishing codePush setup process, I've started to see a warning like:
Warning: Stateless function components cannot be given refs
(See ref "rootComponent" in App created by CodePushComponent).
Attempts to access this ref will fail.
Currently, I have a setup file which is responsible for defining the main component, which is just like:
setup.js
// ...
let App = () => (
<Provider store={store}>
<StyleProvider style={theme}>
<RouterWithRedux scenes={scenes} />
</StyleProvider>
</Provider>
);
module.exports = codePush(App);
index.ios.js / index.android.js
import {AppRegistry} from 'react-native';
const App = require('./config/setup');
AppRegistry.registerComponent('MyApp', () => App);
Except for a _ref_ used on a TextInput, defined on a component with state, I do not use any other _refs_. Removing codepush() makes this warning disappear.
Hi @diegocouto, thank you for reporting the issue. Also please sorry for late reply.
The issue is caused by this line of code. But the root cause of the issue is that stateless component is in use. Our demo app extends React.Component: class CodePushDemoApp extends Component { and use it further with codePush decorator: CodePushDemoApp = CodePush(codePushOptions)(CodePushDemoApp);
To fix the issue could you please try the following:
setup.js
class MyRoot extends Component {
...
render() {
return <div />
}
}
MyRoot = codePush(MyRoot);
let App = () => (
<Provider store={store}>
<MyRoot />
</Provider>
);
module.exports = App;
I've also found the code sample that uses the same approach.
Please let me know if it helps or if you have any issues.
@diegocouto, just a friendly ping.
Hi, @sergey-akhalkov! Thank you for your detailed response. 馃槃 I'll be working on this tomorrow and, as soon as I finish this and some other changes I'll update this issue, ok?
Thanks again! 馃槈
UPDATE
Yep, following this approach, it was possible to get rid of the warning. Thanks! 馃憤
@diegocouto, great! Closing this, please feel free to reopen if needed.
Most helpful comment
Hi @diegocouto, thank you for reporting the issue. Also please sorry for late reply.
The issue is caused by this line of code. But the root cause of the issue is that stateless component is in use. Our demo app extends React.Component:
class CodePushDemoApp extends Component {and use it further with codePush decorator:CodePushDemoApp = CodePush(codePushOptions)(CodePushDemoApp);To fix the issue could you please try the following:
setup.js
I've also found the code sample that uses the same approach.
Please let me know if it helps or if you have any issues.