
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@nrk/custom-element-to-react
Advanced tools
Converts a custom element to a React component, with props and events.
npm install @nrk/custom-element-to-react
Given a custom element:
// my-element.js
export default class MyElement extends HTMLElement { /* ... */ }
convert it to React component by passing in its class definition and a list of props and custom event names:
import React from 'react'
import ReactDOM from 'react-dom'
import customElementToReact from '@nrk/custom-element-to-react'
import element from './my-element.js'
const MyElement = customElementToReact(element, {
props: ['prop1', 'prop2'], // Optional. Prop names to register in React
customEvents: ['event1', 'event2'], // Optional. Custom events names to register in React
suffix: '123' // Optional. Adds a suffix to inner custom element tag name before registering. Use to control tag name of custom element. Default: 'react'
})
ReactDOM.render(<MyElement />, document.getElementById('div'))
forwardRef
provides access to the underlying CustomElement (DOM) itself instead of the React component.
<MyElement
ref={(comp) => console.log('MyElement React Component:', comp)}
forwardRef={(node) => console.log('MyElement actual DOM Element:', node)}
/>
If you're going to use this module to render a component in NodeJS, you should
mock HTMLElement
globally in order to make MyElement extends HTMLElement
valid:
if (typeof window !== 'undefined' && !global.HTMLElement) {
global.HTMLElement = class {}
}
First clone @nrk/custom-element-to-react
and install its dependencies:
git clone git@github.com:nrkno/custom-element-to-react.git
cd custom-element-to-react
npm install # Installs dependencies for all packages
npm start # Your browser will open documentation with hot reloading
After having applied changes, remember to build before pushing the changes upstream.
git checkout -b feature/my-changes
# update the source code
npm run build # Builds all the packages
git commit -am "Add my changes"
git push origin feature/my-changes
# then make a PR to the master branch,
# and assign another developer to review your code
FAQs
Convert custom element to React component
The npm package @nrk/custom-element-to-react receives a total of 12 weekly downloads. As such, @nrk/custom-element-to-react popularity was classified as not popular.
We found that @nrk/custom-element-to-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 126 open source maintainers 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.