• 赚钱入口【需求资源】限时招募流量主、渠道主,站长合作;【合作模式】CPS长期分成,一次推广永久有收益。主动打款,不扣量;

TypeError: setResult is not a function

JavaScript cps12345 1年前 (2020-07-21) 194次浏览 0个评论

代码

const {result, setResult} = useState([]);

 useEffect(() => {
       axios(proxyurl + url)  
            .then(res => res.text)
            .then(res => setResult(res))
            .catch(err => console.log(err))
    }, [setResult]);    
    console.log(result);

报错:

TypeError: setResult is not a function

解决方法

这里做错了

<code><span class="kwd">const</span> <span class="pun">{</span><span class="pln">result</span><span class="pun">,</span><span class="pln"> setResult</span><span class="pun">}</span> <span class="pun">=</span><span class="pln"> useState</span><span class="pun">([]);</span> </code>

正确的方式:

<code><span class="kwd">const</span> <span class="pun">[</span><span class="pln">result</span><span class="pun">,</span><span class="pln"> setResult</span><span class="pun">]</span> <span class="pun">=</span><span class="pln"> useState</span><span class="pun">([]);</span></code>
喜欢 (0)

您必须 登录 才能发表评论!