mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-20 20:38:09 +08:00
46 lines
744 B
Markdown
46 lines
744 B
Markdown
---
|
|
order: 3
|
|
title:
|
|
zh-CN: 受控模式
|
|
en-US: Controlled
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
受控模式.
|
|
|
|
## en-US
|
|
|
|
Controlled mode.
|
|
|
|
````jsx
|
|
import { Mention } from 'antd';
|
|
const { toContentState } = Mention;
|
|
|
|
class App extends React.Component {
|
|
state = {
|
|
value: toContentState('@afc163'),
|
|
}
|
|
componentDidMount() {
|
|
this.mention.focus();
|
|
}
|
|
handleChange = (editorState) => {
|
|
this.setState({
|
|
value: editorState,
|
|
});
|
|
}
|
|
render() {
|
|
return (
|
|
<Mention
|
|
ref={ele => this.mention = ele}
|
|
suggestions={['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご']}
|
|
value={this.state.value}
|
|
onChange={this.handleChange}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
|
````
|