docs: fix demo typo

This commit is contained in:
afc163 2020-08-07 17:14:55 +08:00
parent 5447db9239
commit 7502d84d15

View File

@ -7,11 +7,11 @@ title:
## zh-CN ## zh-CN
`beforeUpload` 返回 `false``Promise.reject` 时,只用于拦截上传行为,不会阻止文件进入上传列表([原因](https://github.com/ant-design/ant-design/issues/15561#issuecomment-475108235)。如果需要阻止列表展现,可以参照此例配合 `onChange` 进行实现。 `beforeUpload` 返回 `false``Promise.reject` 时,只用于拦截上传行为,不会阻止文件进入上传列表([原因](https://github.com/ant-design/ant-design/issues/15561#issuecomment-475108235)。如果需要阻止列表展现,可以参照此例配合 `onChange` 进行实现。
## en-US ## en-US
`beforeUpload` only prevent upload behavior when return false or reject promise, the prevented file would still show in file list. Here is the example you can keep prevented files out of list by using `onChange`. `beforeUpload` only prevent upload behavior when return false or reject promise, the prevented file would still show in file list. Here is the example you can keep prevented files out of list by using `onChange`.
```jsx ```jsx
import React, { useState } from 'react'; import React, { useState } from 'react';
@ -22,13 +22,13 @@ const Uploader = () => {
const [fileList, updateFileList] = useState([]); const [fileList, updateFileList] = useState([]);
const props = { const props = {
fileList, fileList,
beforeUpload: (file) => { beforeUpload: file => {
if (file.type !== 'image/png') { if (file.type !== 'image/png') {
message.error(`${file.name} is not a png file`); message.error(`${file.name} is not a png file`);
} }
return file.type === 'image/png'; return file.type === 'image/png';
}, },
onChange: (info) => { onChange: info => {
console.log(info.fileList); console.log(info.fileList);
// file.status is empty when beforeUpload return false // file.status is empty when beforeUpload return false
updateFileList(info.fileList.filter(file => !!file.status)); updateFileList(info.fileList.filter(file => !!file.status));
@ -40,7 +40,7 @@ const Uploader = () => {
<UploadOutlined /> Upload png only <UploadOutlined /> Upload png only
</Button> </Button>
</Upload> </Upload>
) );
}; };
ReactDOM.render(<Uploader />, mountNode); ReactDOM.render(<Uploader />, mountNode);