我正在尝试向我的减速器添加调度。但是,我在语法上有问题。我不确定如何解决此错误。我在reducer中使用POST方法。
export function insertSearchTerm(searchTerm) {
return (dispatch) => {
fetch('http://localhost:3001/api/v1/searches?searchterm='+searchTerm {
headers: {
'Content-Type':'application/json',
},
method:'POST',
body: JSON.stringify(searchTerm) searchTerm
}).then(res => console.log('D') {
dispatch({
type:'INSERT_TOP_SEARCH',
payload: res
})
}
)
}
}
./src/actions/insertSearchTerm.js
Line 4: Parsing error: Unexpected token, expected ","
2 |
3 | return (dispatch) => {
> 4 | fetch('http://localhost:3001/api/v1/searches?searchterm='+ searchTerm {
| ^
5 | headers: {
6 | 'Content-Type':'application/json'
7 | },
答案 0 :(得分:1)
在searchTerm之后添加','
return (dispatch) => {
fetch('http://localhost:3001/api/v1/searches?searchterm='+ searchTerm, {
headers: {
'Content-Type':'application/json'
}
}
}