赞
踩
useForm
is not connected to any Form element. Forget to pass form
prop?当前使用版本
"@designable/core": "^1.0.0-beta.45",
"@designable/formily-antd": "^1.0.0-beta.45",
"@designable/react-settings-form": "^1.0.0-beta.45",
"@formily/antd": "^2.2.29",
"@ice/runtime": "^1.0.0",
"antd": "^4.22.8",
当页面初始化时form对象找不到可关联的Form表单,出现上述警告,我们需要设置根据visible来设置表单
const useResetFormOnCloseModal = ({ form, visible }) => {
const prevVisibleRef = useRef();
useEffect(() => {
prevVisibleRef.current = visible;
}, [visible]);
const prevVisible = prevVisibleRef.current;
useEffect(() => {
if (!visible && prevVisible) {
form.resetFields();
}
}, [visible]);
};
const ModalForm = ({ visible, onCancel }) => {
const [form] = Form.useForm();
useResetFormOnCloseModal({
form,
visible,
});
const onOk = () => {
form.submit();
};
return (
<Modal title="Basic Drawer" visible={visible} onOk={onOk} onCancel={onCancel}>
<Form form={form} layout="vertical" name="userForm">
<Form.Item
name="name"
label="User Name"
rules={[
{
required: true,
},
]}
>
<Input />
</Form.Item>
<Form.Item
name="age"
label="User Age"
rules={[
{
required: true,
},
]}
>
<InputNumber />
</Form.Item>
</Form>
</Modal>
);
};
import React, { useRef } from 'react';
import { useScroll } from 'ahooks';
export default () => {
const ref = useRef(null);
const scroll = useScroll(ref, (val) => val.top > 100 && val.top < 200);
return (
<>
<p>{JSON.stringify(scroll)}</p>
<div
style={{
height: '160px',
width: '160px',
border: 'solid 1px #000',
overflow: 'scroll',
whiteSpace: 'nowrap',
fontSize: '36px',
}}
ref={ref}
>
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. A aspernatur atque, debitis ex
excepturi explicabo iste iure labore molestiae neque optio perspiciatis
</div>
<div>
Aspernatur cupiditate, deleniti id incidunt mollitia omnis! A aspernatur assumenda
consequuntur culpa cumque dignissimos enim eos, et fugit natus nemo nesciunt
</div>
<div>
Alias aut deserunt expedita, inventore maiores minima officia porro rem. Accusamus ducimus
magni modi mollitia nihil nisi provident
</div>
<div>
Alias aut autem consequuntur doloremque esse facilis id molestiae neque officia placeat,
quia quisquam repellendus reprehenderit.
</div>
<div>
Adipisci blanditiis facere nam perspiciatis sit soluta ullam! Architecto aut blanditiis,
consectetur corporis cum deserunt distinctio dolore eius est exercitationem
</div>
<div>Ab aliquid asperiores assumenda corporis cumque dolorum expedita</div>
<div>
Culpa cumque eveniet natus totam! Adipisci, animi at commodi delectus distinctio dolore
earum, eum expedita facilis
</div>
<div>
Quod sit, temporibus! Amet animi fugit officiis perspiciatis, quis unde. Cumque
dignissimos distinctio, dolor eaque est fugit nisi non pariatur porro possimus, quas quasi
</div>
</div>
</>
);
};
文档在此:https://ant-design.antgroup.com/docs/react/customize-theme-cn
碎碎念:其实使用很简单,就是用ConfigProvider包一下你的组件就行了,比4.X版本改色简单多啦~~~~
import { Button, ConfigProvider, Space } from 'antd';
import React from 'react';
const App: React.FC = () => (
<ConfigProvider
theme={{
token: {
// Seed Token,影响范围大
colorPrimary: '#00b96b',
borderRadius: 2,
// 派生变量,影响范围小
colorBgContainer: '#f6ffed',
},
}}
>
<Space>
<Button type="primary">Primary</Button>
<Button>Default</Button>
</Space>
</ConfigProvider>
);
在项目入口的index.less引入并写入下面代码来更改主题,建立一个单独的 less 变量文件,引入这个文件覆盖 antd.less 里的变量
@import '~antd/es/style/themes/default.less';
@import '~antd/dist/antd.less'; // 引入官方提供的 less 样式入口文件
// 下面是你的自定义主题颜色
@primary-color: rgb(201, 75, 24); // primary color for all components
@link-color: rgb(201, 75, 24); // link color
@success-color: #52c41a; // success state color
@warning-color: #faad14; // warning state color
@error-color: #f5222d; // error state color
@font-size-base: 14px; // major text font size
@heading-color: rgba(0, 0, 0, 0.85); // heading text color
@text-color: rgba(0, 0, 0, 0.65); // major text color
@text-color-secondary: rgba(0, 0, 0, 0.45); // secondary text color
@disabled-color: rgba(0, 0, 0, 0.25); // disable state color
@border-radius-base: 2px; // major border radius
@border-color-base: #d9d9d9; // major border color
@box-shadow-base: 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 6px 16px 0 rgba(0, 0, 0, 0.08),
0 9px 28px 8px rgba(0, 0, 0, 0.05); // major shadow for layers
ResizeObserver loop completed with undelivered notifications.
at handleError (http://localhost:3000/js/main.js:2161:58)
at http://localhost:3000/js/main.js:2180:7
简单粗暴解决:所以在报错组件里面,或者全局,添加隐藏这个浮层的样式
//antd组件内 ResizeObserver loop limit exceeded报错隐藏
#webpack-dev-server-client-overlay {
display: none !important;
}
例如下载访问报错 npm/monaco-editor@0.36.1/min/vs/base/worker/workerMain.js
使用国内资源库:
1.https://staticfile.org
CDN 加速由七牛云提供,技术社区掘金支持,资源库库相对也比较丰富.很多年了.
2.https://cdn.baomitu.com/
360 前端静态资源库是由奇舞团支持并维护的开源项目免费 CDN 服务,支持 HTTPS 和 HTTP/2,囊括上千个前端资源库和 Google 字体库。
3.https://cdn.bytedance.com/
字节跳动提供的提供的资源库也比较丰富
4.https://unpkg.zhimg.com
知乎提供的unpkg.com国内的镜像,访问速度快.但是疑似有些限制.
Type 'void' is not assignable to type 'MouseEventHandler<HTMLSpanElement> | undefined'.ts(2322)
index.d.ts(1521, 9): The expected type comes from property 'onClick' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>'
<span className="tableOperationIcon" onClick={handleUpdate(_.id)}> 点击功能 </span>
改成下面写法就可以了
<span className="tableOperationIcon" onClick={() => { handleUpdate(_.id); }} > 点击功能 </span>
按照规定的变量类型,声明变量
声明的时候:any
赋值的时候 as any
解决办法:给组件ITextWidgetProps手动加完善类型
interface ITextWidgetProps {
children?: string;
}
navigate 函数options 配置选项详解如下:
import { useNavigate } from "react-router-dom";
const jumpTo = (name: string) =>{
navigate('/home', { state: { name } });
}
<Card title="XXX" onClick={() => toDetail('送你一朵小红花')}> </Card>
注意事项: 与 history.push 不同,navigate 不会在浏览器历史记录中添加重复的路由记录。navigate({ pathname, state }) 这种写法会添加新的历史记录。
在 React Router 中,可以通过 useLocation hook 来获取传递的参数和路径信息。
import { useLocation } from "react-router-dom";
const location = useLocation();
const data = location.state;
console.log("-----", data);
举个例子:
传递参数
import { useNavigate } from 'react-router';
const navigateTo = useNavigate();
const go = (e) => {
navigateTo('/xiaojin?id=' + e.id);
};
获取参数
import { useSearchParams } from 'react-router-dom';
const [search] = useSearchParams();
console.log(search.get('id'));
导致这种问题发生一般都是因为你滚动的功能应该绑定到某个元素上面,而不是直接用window
使用ref,配合页面元素滚动 解决问题
.xiaojin-demo{
height: calc(100vh - 100px);
overflow-y: scroll;
}
import React, { useRef } from "react";
const ref = useRef(null);
const backToTop = ()=>{
ref.current && ref.current.scrollTo({ top: 0, behavior: 'smooth' })
}
<div className="resource-approve" ref={ref}>
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. A aspernatur atque, debitis ex
excepturi explicabo iste iure labore molestiae neque optio perspiciatis
</div>
<div>
Aspernatur cupiditate, deleniti id incidunt mollitia omnis! A aspernatur assumenda
consequuntur culpa cumque dignissimos enim eos, et fugit natus nemo nesciunt
</div>
<div>
Alias aut deserunt expedita, inventore maiores minima officia porro rem. Accusamus ducimus
magni modi mollitia nihil nisi provident
</div>
<div>
Alias aut autem consequuntur doloremque esse facilis id molestiae neque officia placeat,
quia quisquam repellendus reprehenderit.
</div>
<div>
Adipisci blanditiis facere nam perspiciatis sit soluta ullam! Architecto aut blanditiis,
consectetur corporis cum deserunt distinctio dolore eius est exercitationem
</div>
<div>Ab aliquid asperiores assumenda corporis cumque dolorum expedita</div>
</div>
import {setNpmCDNRegistry} from '@designable/react-settings-form'
setNpmCDNRegistry('//fastly.jsdelivr.net/npm') // 也可以把资源下载到本地,使用本地的域名
By using the .config
method we can configure the monaco loader. By default all sources come from CDN, you can change that behavior and load them from wherever you want
import loader from '@monaco-editor/loader';
// you can change the source of the monaco files
loader.config({ paths: { vs: '...' } });
// you can configure the locales
loader.config({ 'vs/nls': { availableLanguages: { '*': 'de' } } });
// or
loader.config({
paths: {
vs: '...',
},
'vs/nls' : {
availableLanguages: {
'*': 'de',
},
},
});
loader.init().then(monaco => { /* ... */ });
var config = {
paths: {
vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.36.1/min/vs'
}
};
也可以把资源下载到本地,使用本地的域名
接下来请求里就没有之前的了,也可以把cdn替换为本地的资源哦~~
failed to load config from xxx\vite.config.ts
error when starting dev server:
Error: The package “@esbuild/win32-x64” could not be found, and is needed by esbuild.
If you are installing esbuild with npm, make sure that you don’t specify the
“–no-optional” or “–omit=optional” flags. The “optionalDependencies” feature
of “package.json” is used by esbuild to install the correct binary executable
for your current platform.
手动安装完成之后,再次运行 npm run dev 即可
npm i @esbuild
npm run dev
在vite.config.ts里添加一点代码,然后重启项目即可
server: {
watch: {
usePolling: true, // 修复vite热更新失效
},
Cell
.Warning: Each child in a list should have a unique "key" prop.
Check the render method of `Cell`. See https://reactjs.org/link/warning-keys for more information.
at InternalTag (http://127.0.0.1:3000/js/p_index-8af48807.js:103620:18)
at Cell (http://127.0.0.1:3000/js/p_index-8af48807.js:144321:70)
at tr
at BodyRow (http://127.0.0.1:3000/js/p_index-8af48807.js:143839:70)
at ImmutableComponent (http://127.0.0.1:3000/js/p_index-8af48807.js:53249:5)
at tbody
at Body (http://127.0.0.1:3000/js/p_index-8af48807.js:144186:70)
at ImmutableComponent (http://127.0.0.1:3000/js/p_index-8af48807.js:53249:5)
at table
at div
at div
at div
at Provider (http://127.0.0.1:3000/js/p_index-8af48807.js:53292:22)
at Table (http://127.0.0.1:3000/js/p_index-8af48807.js:145365:58)
at ImmutableComponent (http://127.0.0.1:3000/js/p_index-8af48807.js:53217:61)
看到 cell 我们就去找 .map循环的关键字,或者是其他循环的,我们一定是循环的时候忘记加key 了
举个栗子
{
title: 'name',
dataIndex: 'name',
key: 'name',
render: (nameList) => (
nameList.map((_) => {
return <Tag color="green">{_}</Tag>;
})
),
}
改为
{
title: 'name',
dataIndex: 'name',
key: 'name',
render: (nameList) => (
nameList.map((_, index) => {
return <Tag color="green" key={index}>{_}</Tag>;
})
),
}
react-dom.development.js:16227 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
at Object.throwInvalidHookError (react-dom.development.js:16227:1)
at Object.useContext (react.development.js:1618:1)
at useNavigate (index.js:198:1)
at addApplication (index.tsx:67:1)
at handleClick (button.js:130:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
at invokeGuardedCallback (react-dom.development.js:4277:1)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
at executeDispatch (react-dom.development.js:9041:1)
报错原因,我在页面使用了这个代码
import { useNavigate } from 'ice';
export default function Home() {
const navigate = useNavigate();
useEffect(() => {
navigate('/logout', { replace: true });
}, []);
return (
<>
<h2>Home Page</h2>
</>
);
}
欢迎大家指出文章需要改正之处~
学无止境,合作共赢
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。