Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
react-contenteditable
Advanced tools
Readme
React component for a div with editable contents
npm install react-contenteditable
import React from 'react'
import ContentEditable from 'react-contenteditable'
class MyComponent extends React.Component {
constructor() {
super()
this.contentEditable = React.createRef();
this.state = {html: "<b>Hello <i>World</i></b>"};
};
handleChange = evt => {
this.setState({html: evt.target.value});
};
render = () => {
return <ContentEditable
innerRef={this.contentEditable}
html={this.state.html} // innerHTML of the editable div
disabled={false} // use true to disable editing
onChange={this.handleChange} // handle innerHTML change
tagName='article' // Use a custom HTML tag (uses a div by default)
/>
};
};
prop | description | type |
---|---|---|
innerRef | element's ref attribute | Object | Function |
html | required: innerHTML of the editable element | String |
disabled | use true to disable editing | Boolean |
onChange | called whenever innerHTML changes | Function |
onBlur | called whenever the html element is blurred | Function |
onFocus | event fires when an element has received focus | Function |
onKeyUp | called whenever a key is released | Function |
onKeyDown | called whenever a key is pressed | Function |
className | the element's CSS class | String |
style | a collection of CSS properties to apply to the element | Object |
If you are using hooks, please see this issue. Using this component with useState
doesn't work, but you can still use useRef
:
const text = useRef('');
const handleChange = evt => {
text.current = evt.target.value;
};
const handleBlur = () => {
console.log(text.current);
};
return <ContentEditable html={text.current} onBlur={handleBlur} onChange={handleChange} />
You can try react-contenteditable right from your browser to see if it fits your project's needs:
<div>
with a default value.FAQs
React component representing an element with editable contents
The npm package react-contenteditable receives a total of 89,989 weekly downloads. As such, react-contenteditable popularity was classified as popular.
We found that react-contenteditable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.