1
我正在按照來自lynda的教程:「構建和部署完整堆棧響應應用程序」中的「注入中繼網絡層」一章。有在index.js,試圖建立一個網絡層,程序編譯成功,但我收到在瀏覽器中出現以下錯誤:React relay injectNetworkLayer不是函數
類型錯誤:__WEBPACK_IMPORTED_MODULE_4_react_relay ___ default.a.injectNetworkLayer不是一個函數
index.js文件是:
import React from 'react'
import ReactDOM from 'react-dom'
import {Router, browserHistory, applyRouterMiddleware} from 'react-router'
import Routes from './routes'
import Relay from 'react-relay'
import useRelay from 'react-router-relay'
import {RelayNetworkLayer, urlMiddleware} from 'react-relay-network-layer'
import {relayApi} from './config/endpoints'
import auth from './utils/auth'
const createHeaders =() => {
let idToken = auth.getToken()
if (idToken) {
return {
'Authorization': `Bearer ${idToken}`
}
} else {
return {}
}
}
Relay.injectNetworkLayer(
new RelayNetworkLayer([
urlMiddleware({url: (req) => relayApi,}),
next => req => {
req.headers = {
...req.headers,
...createHeaders()
}
return next(req)
},
],{disableBatchQuery: true})
)
ReactDOM.render(
<Router
environment={Relay.Store}
render={applyRouterMiddleware(useRelay)}
history={browserHistory}
routes={Routes}
/>,
document.getElementById('root')
)
什麼都來嘗試做修復它? –