redux-localstorage实现错误:警告:propType失败:提供给`Provider`的`function`类型的prop`store`无效,期望`object`

时间:2017-08-15 19:23:40

标签: reactjs redux local-storage react-redux

我目前正在实施redux-localstorage

但我遇到以下错误:警告:propType失败:提供给store的类型为function的无效道具Provider,预计object

这是我的index.js文件 - 我在这里缺少什么?

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { compose, createStore, applyMiddleware } from 'redux';
import ReduxThunk from 'redux-thunk';
import { createLogger } from 'redux-logger';
import persistState from 'redux-localstorage'

import App from './components/app';
import reducers from './reducers';

const logger = createLogger({ collapsed: true });
const enhancer = compose(
  ReduxThunk,
  logger,
  persistState(null, 'redux')
);

const store = createStore(reducers, enhancer);

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>
  , document.querySelector('.container'));

2 个答案:

答案 0 :(得分:0)

看起来你已经找到了persistState的签名错误,请尝试不带参数调用它。

https://github.com/elgerlambert/redux-localstorage#persiststatepaths-config

答案 1 :(得分:0)

您需要提供thunk作为applyMiddleware函数的参数:

   <input type="text" id="text" name="search">
<table id="table_data">
        <tr class="listR"><td>PHP</td></tr>
        <tr class="listR"><td>MySql</td></tr>
        <tr class="listR"><td>AJAX</td></tr>
        <tr class="listR"><td>jQuery</td></tr>
        <tr class="listR"><td>JavaScript</td></tr>
        <tr class="listR"><td>HTML</td></tr>
        <tr class="listR"><td>CSS</td></tr>
        <tr class="listR"><td>CSS3</td></tr>
</table>

$("#textbox").on('keyup',function(){
        var f = $(this).val();
      $("#table_data tr.listR").each(function(){
            if ($(this).text().search(new RegExp(f, "i")) < 0) {
                $(this).fadeOut();
             } else {
                 $(this).show();
            }
        });
    });

您还需要为记录器做同样的事情