【问题标题】:'value' is attached to all hooks'value' 附加到所有钩子上
【发布时间】:2021-12-29 07:33:07
【问题描述】:

无论我使用什么钩子,如果我按保存,“值”会自动出现。因为这个,我压力很大。 如果你能帮助我,我会很感动的。

enter image description here

import axios from 'axios';
import React, { value useEffect, value useState } from 'react';

function TestPage() {
  console.log(process.env.NEXT_PUBLIC_WECODE_URI);

  const [state, setState] = useState('');

  const customFetch = async () => {
    const results = await axios.get(`${process.env.NEXT_PUBLIC_WECODE_URI}/testapi`);
  };

  useEffect(() => {
    customFetch();
  }, []);

  return <div>{state}</div>;
}

export default TestPage;

【问题讨论】:

  • 去掉单词值。这不是有效的打字稿
  • 如果被移除,它将继续重新创建。 :(

标签: reactjs typescript next.js


【解决方案1】:
import axios from 'axios';
import React, { useEffect, useState } from 'react';

function TestPage() {
  console.log(process.env.NEXT_PUBLIC_WECODE_URI);

  const [state, setState] = useState();

  const customFetch = async () => {
    const results = await axios.get(`${process.env.NEXT_PUBLIC_WECODE_URI}/testapi`);
    setState(results)
  };

  useEffect(() => {
    customFetch();
  }, []);

  return <div>{state}</div>;
}

export default TestPage;

【讨论】:

  • 当你使用 import from any package 时,vscode 会自动为 value 添加前缀,因为配置 prettier 可能是错误的,在扩展中禁用 prettier 并重新启用它
  • 非常感谢!我想这是你说的问题!
猜你喜欢
  • 1970-01-01
  • 2011-07-09
  • 1970-01-01
  • 2013-02-17
  • 1970-01-01
  • 2011-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多