React-native-ui-kitten: Warning during state update.

Created on 23 Aug 2020  路  4Comments  路  Source: akveo/react-native-ui-kitten

I've got this error:

Warning: Cannot update during an existing state transition (such as withinrender). Render methods should be a pure function of props and state.

my code is:

const [value, setValue] = React.useState("");

```
const onChangeTextReset = React.useCallback(
(val: string) => {
setValue(val);
},
[setValue, setError]
);



label={labelWithError}
style={style.addInput}
status="basic"
placeholder="ID"
value={value}
onChangeText={onChangeTextReset}
/>

Help wanted Duplicate

Most helpful comment

@artyorsh I understand the workaround specified in that ticket. But that is simply a workaround due to an issue with this library performing a forceUpdate during a render function.

I don't have the current capacity to fix this issue right now but looking at the code of ModalPanel, I think I understand the basic issue.

Can you please keep this issue open so it can be tracked. That way either myself or another developer can come back and fix the issue.

All 4 comments

Hi, we have the same issue in our project when we set a state in a modal component.
Do you have an idea of when it will be fixed ?

Same issue as well, here is a minimal reproduction that is a slight variation from the example in the docs.

For visibility, the issue title should be changed to highlight that this issue is caused by the Modal component (most likely the forcedUpdate during ModalPanel.update)

import React from 'react';
import { StyleSheet } from 'react-native';
import { Button, Card, Layout, Modal, Text } from '@ui-kitten/components';

export const ModalSimpleUsageShowcase = () => {

  const [visible, setVisible] = React.useState(false);
  const [text, setText] = React.useState("Welcome to UI Kitten 馃樆");

  return (
    <Layout style={styles.container} level='1'>

      <Button onPress={() => setVisible(true)}>
        TOGGLE MODAL
      </Button>

      <Modal visible={visible}>
        <Card disabled={true}>
          <Text>{text}</Text>
          <Button onPress={() => setText("Check console for warning!")}>
            Change Text
          </Button>
        </Card>
      </Modal>

    </Layout>
  );
};

const styles = StyleSheet.create({
  container: {
    minHeight: 192,
  },
});

@artyorsh I understand the workaround specified in that ticket. But that is simply a workaround due to an issue with this library performing a forceUpdate during a render function.

I don't have the current capacity to fix this issue right now but looking at the code of ModalPanel, I think I understand the basic issue.

Can you please keep this issue open so it can be tracked. That way either myself or another developer can come back and fix the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

evangunawan picture evangunawan  路  3Comments

sovannvin picture sovannvin  路  3Comments

sobiso picture sobiso  路  3Comments

simonsankar picture simonsankar  路  3Comments

chamatt picture chamatt  路  3Comments