1

我遇到了以下问题:每次我searchString在我的 redux 存储中更新时CustomFilterConnectedComponent,我传递给Griddle的 都会失去焦点,我不明白为什么会发生这种情况。

这是我基于文档的代码:

哑组件:

import { connect } from "react-redux";

const CustomFilterComponent = (props) => (
  <input
    value={props.searchString}
    onChange={(e) => { props.setSearchString(e.target.value); }}
  />
);

智能组件:

const CustomFilterConnectedComponent = connect(
  (state: TRootReducerState) => {
    return ({
      searchString: state.searchString,
    });
  },
  (dispatch: any) => ({
    setSearchString: (e) => dispatch(setSearchStringActionCreator(e))
  })
)(CustomFilterComponent);

用法:

class SomePage extends React.Component<Props, {}> {
  render() {
  return (
        <div>

          {/* keypress - everything is ok, value is updated & focus is not lost*/}              
          <CustomFilterConnectedComponent/> 

          <Griddle
            components={{
                /* keypress - value is updated, but focus lost */                  
                Filter: CustomFilterConnectedComponent 
            }}
            storeKey="griddleStore"
            data={this.props.requests as any}
          />
     </div>
     );
   }
}

这是github上问题的链接。

4

1 回答 1

1

我已经把你的复制品变成了一个故事,没有看到你的焦点问题。

也就是说,我最好的猜测是这个问题与如何props.requests提供给SomePage.

于 2017-11-14T07:14:53.233 回答