小编Yeo*_*_Li的帖子

类型“从不”上不存在属性“值”。在 mui 中使用 useRef 钩子时

我正在使用Material UI来构建登录和注册页面,useRef用于返回TextFiled ref 实例,并xxxRef.current.value获取输入值。

我可以顺利运行我的项目并且可以value正确获取?但是控制台总是提醒我:

Property 'value' does not exist on type 'never'.
Run Code Online (Sandbox Code Playgroud)

这是我的代码片段?

const accountRef = useRef();

<TextField
            variant="outlined"
            margin="normal"
            required
            fullWidth
            id="account"
            label="Account"
            name="account"
            autoComplete="account"
            autoFocus
            defaultValue={account}
            inputRef={accountRef}
/>


const payload = {
      account: accountRef.current?.value ?? '',
      password: passwordRef.current?.value ?? '',
      nickname: nicknameRef.current?.value ?? '',
};
Run Code Online (Sandbox Code Playgroud)

typescript ecmascript-6 reactjs material-ui react-hooks

8
推荐指数
3
解决办法
4702
查看次数

错误:[vuex]期望将字符串作为类型,但未定义

正在学习Vuex。我针对示例项目文档编写了一个简单的登录页面,但是当我尝试使用动作功能时,开发人员工具只是警告我

错误信息

这是我的代码:

src / views / Login.vue

handleLogin (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          // to do
          this.$store.dispatch('user/login', this.loginUser)
        } else {
          ......
          })
        }
      })
Run Code Online (Sandbox Code Playgroud)

src / store / index.js

import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/User/user'
// import info from './modules/info'

Vue.use(Vuex)

export default new Vuex.Store({
  strict: false,
  modules: {
    user,
    // info
  }
})
Run Code Online (Sandbox Code Playgroud)

/src/store/modules/User/actions.js

export const userActions = {
  login({commit}, loginUser) {
    commit(LOGIN)
    axios.post(`${ API_BASE_USER …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 vue.js vuex

3
推荐指数
2
解决办法
2955
查看次数

tsx 找不到模块“xxx”

我在用yarn v2安装依赖包,用yarn startcommand启动项目很顺利,但是vscode老是提示我找不到本地模块。

在此处输入图片说明

这是我的tsconfig.json文件:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ]
}
Run Code Online (Sandbox Code Playgroud)

这是我的文件夹结构:

在此处输入图片说明

typescript tsx yarnpkg yarn-v2

3
推荐指数
1
解决办法
1200
查看次数

React eslint 错误?组件定义缺少显示名称

使用Reac.memo包裹我的功能组件,它可以流畅运行,但eslint总是让我想起了两个错误:

error    Component definition is missing display name  react/display-name

error    'time' is missing in props validation         react/prop-types
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

type Data = {
  time: number;
};
const Child: React.FC<Data> = React.memo(({ time }) => {
  console.log('child render...');
  const newTime: string = useMemo(() => {
    return changeTime(time);
  }, [time]);

  return (
    <>
      <p>Time is {newTime}</p>
      {/* <p>Random is: {children}</p> */}
    </>
  );
});
Run Code Online (Sandbox Code Playgroud)

我的整个代码:

import React, { useState, useMemo } from 'react';

const Father = () => {
  const [time, …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs eslint

2
推荐指数
1
解决办法
6216
查看次数