我正在使用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) 正在学习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) 我在用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)
这是我的文件夹结构:
使用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 ×3
ecmascript-6 ×2
reactjs ×2
eslint ×1
javascript ×1
material-ui ×1
react-hooks ×1
tsx ×1
vue.js ×1
vuex ×1
yarn-v2 ×1
yarnpkg ×1