我在我的文件中导入了一个json文件,我创建了一个这样的动作:
import jsonData from './data/account_list_response.json';
const inAccountsList = () => {
store.dispatch({
type: 'ACCOUNT_LIST',
state: {
accounts: jsonData
}
});
};
然后,我在帐户列表容器中将帐户设为prop,如下所示:
function mapStateToProps(state) {
return { accounts: state.get('accounts').map(account => account.toJS()) };
}
最后
const AccountList = ({ accounts }) => (
<div className="account-list">
<h4 className="table-header">Accounts</h4>
<Table hover>
<thead>
<tr>
<th>#</th>
<th>Account Number</th>
<th>Description</th>
<th>Balance</th>
<th>Available Balance</th>
<th>Currency</th>
</tr>
</thead>
<tbody>
{accounts.map((account, i) =>
<AccountEntry
key={account.id} idx={i + 1}
{...account}
/>
)}
</tbody>
</Table>
</div>
);
发生错误提供给accounts
的类型object
的无效道具AccountList
,预期是一个数组。为什么???