小编yzh*_*han的帖子

如何在状态更改时正确更新 React Native swiper 组件?

我有一个使用react-native-swiper模块的本机组件。swiper 中的一张幻灯片包含在组件状态中设置的文本。在组件中,我还有一个带有表单的模态,当用户尝试从模态保存输入数据时,它会更改状态的文本。

问题是:在我当前的实现中,每次我保存新数据时,swiper 都会被拖到最后一张幻灯片,并重新渲染幻灯片(这个过程很滞后)。所以我想知道更顺畅地更新幻灯片的最佳方法是什么?

下面是我的组件:

'use strict';

import React from 'react';
import { 
  Dimensions, 
  StyleSheet, 
  View, 
  Text, 
  ScrollView,
  AlertIOS,
  AsyncStorage
} from 'react-native';
import { StackNavigator } from 'react-navigation';
import Swiper from 'react-native-swiper';
import Button from 'react-native-button';
import { saveName, getName } from '../Utils/dataService';
import { showAlert } from '../Utils/alert';
import HeaderSection from './HeaderSection';
import { styles } from '../Styles/Styles';
import { renderPagination } from './renderPagination';

class MainView extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      name: …
Run Code Online (Sandbox Code Playgroud)

swiper reactjs react-native react-native-swiper

6
推荐指数
1
解决办法
8846
查看次数

使用 AJAX 或 Socket.io 自动完成?

我正在使用 Node.js 和 Express 构建一个搜索应用程序,并且我想添加自动完成功能。之前我使用 Socket.io 构建了一个聊天应用程序,所以我首先想到的是 Socket.io。

但我做了一些研究,看起来很多人都在使用 AJAX 进行自动完成,那么这两种实现之间有什么区别呢?

我对 TCP 和 HTTP 协议没有太多经验,所以我真的很感谢菜鸟们的清晰简单的答案:)

ajax node.js socket.io

3
推荐指数
1
解决办法
1644
查看次数