-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from niuware/development
Rewrite from class to function component
- Loading branch information
Showing
11 changed files
with
400 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,36 @@ | ||
import React from 'react' | ||
import React, { FunctionComponent, useRef, Ref, MutableRefObject } from 'react' | ||
import MUIRichTextEditor from '../../' | ||
|
||
class RefSave extends React.Component { | ||
private ref: any | ||
constructor(props: any) { | ||
super(props) | ||
this.ref = React.createRef() | ||
} | ||
const RefSave: FunctionComponent = (props) => { | ||
|
||
const ref = useRef() | ||
|
||
handleClick = () => { | ||
this.ref.current.save() | ||
const handleClick = () => { | ||
(ref as any).current.save() | ||
} | ||
|
||
handleSave = (data: string) => { | ||
const handleSave = (data: string) => { | ||
console.log(data) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
Save editor state from external button: | ||
<button style={{ | ||
marginLeft: 5, | ||
padding: 5 | ||
}} | ||
onClick={this.handleClick}> | ||
Save | ||
</button> | ||
<MUIRichTextEditor | ||
label="Type something here..." | ||
onSave={this.handleSave} | ||
ref={this.ref} | ||
controls={["bold", "italic", "underline", "quote", "clear"]} | ||
/> | ||
</div> | ||
) | ||
} | ||
return ( | ||
<div> | ||
Save editor state from external button: | ||
<button style={{ | ||
marginLeft: 5, | ||
padding: 5 | ||
}} | ||
onClick={handleClick}> | ||
Save | ||
</button> | ||
<MUIRichTextEditor | ||
label="Type something here..." | ||
onSave={handleSave} | ||
ref={ref} | ||
controls={["bold", "italic", "underline", "quote", "clear"]} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default RefSave |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export {default} from './src/MUIRichTextEditor' | ||
export {default} from './src/MUIRichTextEditor' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.