gpt4 book ai didi

javascript - 第 105 行 :14: 'accountSelector' is not defined no-undef

转载 作者:行者123 更新时间:2023-11-29 22:46:32 25 4
gpt4 key购买 nike

有人可以简单地解释一下出了什么问题,这样我就知道如何解决这个问题,并在下次遇到它时可以处理它。我已经查看了我可以在 stackoverflow 上找到的所有相关问题,但无法修复它,如果我错过了一个可以回答这个问题的问题,请链接它。我过去遇到过这个错误,但通常那只是因为我有错字(例如大写字母而不是小写字母)或者没有正确导入某些东西,但据我所知这次情况并非如此。第一个代码 app.js第二代码 interactions.js

这是我的代码

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Navbar from './Navbar'
import Web3 from 'web3';
import { connect } from 'react-redux'
// import Token from '../abis/Token.json'
import {
loadWeb3,
loadAccount,
loadToken,
loadExchange
} from '../store/interactions'

class App extends Component {
componentWillMount() {
this.loadBlockchainData(this.props.dispatch)
}
async loadBlockchainData(dispatch) {
const web3 = loadWeb3(dispatch)
const network = await web3.eth.net.getNetworkType()
const networkId = await web3.eth.net.getId()
const accounts = await loadAccount(web3, dispatch) // <<--
const token = loadToken(web3, networkId, dispatch)
loadExchange(web3, networkId, dispatch)
}
// ......................

function mapStateToProps(state) {
return {
account: accountSelector(state)
}
}

export default connect(mapStateToProps)(App);


import Web3 from 'web3'
import {
web3Loaded,
web3AccountLoaded,
tokenLoaded,
exchangeLoaded
} from './actions'
import Token from '../abis/Token.json'
import Exchange from '../abis/Exchange.json'

export const loadWeb3 = (dispatch) => {
const web3 = new Web3(Web3.givenProvider || 'http://localhost:7545')
dispatch(web3Loaded(web3))
return web3
}

export const loadAccount = async (web3, dispatch) => {
const accounts = await web3.eth.getAccounts()
const account = accounts[0]
dispatch(web3AccountLoaded(account))
return account
}

export const loadToken = async (web3, networkId, dispatch) => {
try {
const token = new web3.eth.Contract(Token.abi, Token.networks[networkId].address) // new 이거 의존성(버전) 문제 이거 조심!!!!!
dispatch(tokenLoaded(token))
return token
} catch (error) {
window.alert('Contract not deployed to the current network. Please select another network with Metamask.')
return null
}
}

export const loadExchange = async (web3, networkId, dispatch) => {
try {
const exchange = new web3.eth.Contract(Exchange.abi, Exchange.networks[networkId].address)
dispatch(exchangeLoaded(exchange))
return exchange
} catch (error) {
window.alert('Contract not deployed to the current network. Please select another network with Metamask.')
return null
}
}

我现在不知道为什么这会发生在我身上但如果你知道这个问题,请告诉我这个问题

最佳答案

问题似乎是您没有在任何地方定义或导入 accountSelector 函数。

您通常在 reducer 定义文件中定义 Redux 选择器函数:它们将当前 Redux 存储状态作为参数(以及可选的连接组件 props)并返回要在 MapStateToProps 对象属性中使用的值。例如。

export const accountSelector = (state) => state.account

您可以在 dedicated Redux resources page 上阅读更多关于选择器的信息

关于javascript - 第 105 行 :14: 'accountSelector' is not defined no-undef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58333781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com