Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error and warning: "Cannot update during an existing state transition an error", using react-native-router-flux and redux-form Field #2201

Closed
OrianeInMoon opened this issue Aug 8, 2017 · 6 comments

Comments

@OrianeInMoon
Copy link

bug

using react-native-router-flux with <Field /> from redux-form, I run into warnings and an error.

versions

"react": "16.0.0-alpha.12",
"react-native": "0.46.4",
"react-native-router-flux": "^4.0.0-beta.16",
"react-redux": "^5.0.5",
"redux": "^3.7.2",
"redux-form": "^7.0.1",

expected behavior

No warnings and no error

actual behavior

errors

  • a warning:

Warning: Cannot update during an existing state transition (such as within renderor another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved tocomponentWillMount`

  • an error:

Uncaught RangeError: Maximum call stack size exceeded

observations

  • The problem came after passing mapStateToProps to ConnectedRouter:
const ConnectedRouter = connect(mapStateToProps, null, mergeProps)(Router);

I just did a little digging. Would you mind explaining why does the component need to be stateless?, I suspect that the <Field /> component is not stateless and so, not compatible with the react-native-router-flux render.

@necsoft resolved the problem switching from

class App extends Component {

to

const App = () => {...}

updating could be solution, or was a solution at this time and with react-router.

step to reproduce

<ConnectedRouter />
  <Scene contentComponent={PageHome}/>
    <MyReduxForm />
      <Field />
  • <ConnectedRouter />
const ConnectedRouter = connect(mapStateToProps, null, mergeProps)(Router);
  • <Scene />
<Scene
  key="pagehome"
  component={PageHome}
  title="Home"
/>
  • <Page />
const PageHome = ({ onSubmit }) => {
  return (
    <View>
      <MyReduxForm onSubmit={onSubmit} />
    </View>
  );
};

const mapStateToProps = (dispatch) => {
  return {};
};

const mapDispatchToProps = (dispatch) => {
  return {
    onSubmit: () => console.log('submit')),
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(PageAccount);
  • <Form />
import { Field, reduxForm } from 'redux-form';

let MyReduxForm ({ handleSubmit, onSubmit }) =>
<View>
  <Text style={styles.label}>{I18n.t('strings.formAccount.fields.email.label')}</Text>
  <Field
    name="email"
    type="text"
  />
</View>


MyReduxForm = reduxForm({
  form: 'myReduxForm',
  validate,
})(MyReduxForm);

FormAccount = connect()(MyReduxForm);
@aksonov
Copy link
Owner

aksonov commented Aug 8, 2017

I don't understand - why MyReduxForm is children of Scene ?

@MaxInMoon
Copy link
Contributor

@aksonov the schema is very trivial. In fact MyReduxForm is a children of the Scene component's PageHome

@MaxInMoon
Copy link
Contributor

@aksonov did you ever used/encountered a real working exemple with redux-form?

@aksonov
Copy link
Owner

aksonov commented Aug 8, 2017

No, I don't have any. Please give me link to repo so I can reproduce that issue. Please also check pure react-navigation, maybe the issue is from there:
react-navigation/react-navigation#1589

@MaxInMoon
Copy link
Contributor

@aksonov I'll do my best to provide one before tomorrow

@aksonov
Copy link
Owner

aksonov commented Aug 16, 2017

Closed due inactivity

@aksonov aksonov closed this as completed Aug 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants