0

我最近开始在 react-native 中编码,经过几年的“正常”ReactJS 用于网络,所以我正在使用我一直使用的相同“技术”,但它似乎不起作用一样的方法。

我有这个模式,从 UI-Kitten 5 导入:

        <Modal visible={this.state.deviceFoundVisible} backdropStyle={StyleConnectScreen.backdrop}>
          <Card
            appearance={'filled'}
            status={'success'}
            header={(props) => (
              <Layout style={StyleConnectScreen.modal_header}>
                <Text category={'h3'}>{translate('device_found')}</Text>
              </Layout>
            )}
            footer={(props) => (
              <Layout style={StyleConnectScreen.layout_modal_buttons} level={'2'}>
                <Button style={StyleConnectScreen.button_modal} onPress={this.onDeviceFoundCancelHandler}>
                  <Text>{translate('cancel')}</Text>
                </Button>
                <Button status={'success'} style={StyleConnectScreen.button_modal} onPress={this.onDeviceFoundConfirmHandler}>
                  <Text>{translate('confirm')}</Text>
                </Button>
              </Layout>
            )}
          >
            <Layout style={StyleConnectScreen.modal_content}>
              <Text category={'h6'}>{translate('connect_to_device')}: </Text>
              <Text style={{fontFamily: 'OpenSans-Regular'}} category={'h5'}>{(this.state.foundDevice !== null ? this.state.foundDevice.name : '')}</Text>
            </Layout>
          </Card>
        </Modal>

首先,我非常喜欢 Class Components,可能是因为我从 0.xx 版本开始就使用 React。我仍然使用这些是错的吗?但真正的问题是,当我更改this.state.deviceFoundVisible的状态时,模式会出现,但总是会触发警告:

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

当找到 BLE 设备时,该值会更新,这是由 Promises 完成的。承诺的异步性质是否触发了这一点?

提前致谢!

4

0 回答 0