
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
list-node-hooks
Advanced tools
A React list component that allows you to manipulate dom-nodes on transitions
npm install list-node-hooks --save
A React list component that allows you to manipulate dom-nodes on transitions
When will this be usefull? Well, for animation purposes for instance. It might not be a good idea to manipulate dom-nodes outside of React (anti-pattern), but sometimes you have choose simplicity over correctness and be pragmatic.
This higher order component figures out how it's children change over time, and passes the corresponding dom-nodes to the 'hooks' you've provided.
import listNodeHooks from 'list-node-hooks';
import React, { Component } from 'react';
const hooks = {
listMount(nodes) {
// do something with these nodes...
}
};
// decorate a class
@listNodeHooks(hooks)
class List extends Component {
render() {
return (
<div>
{this.props.children}
</div>
);
}
}
// or shortcut
const List = listNodeHooks(hooks)('div');
class App extends Component {
state = {
items: [
{ id: 1, text: 'item1' },
{ id: 2, text: 'item2' },
{ id: 3, text: 'item3' },
{ id: 4, text: 'item4' }
]
};
render() {
return (
<List>
{ this.state.items.map(({ id, text }) => <div key={id}>{text}</div>) }
</List>
);
}
}
Typical decorator pattern.
'hooks' is an object with certain functions that will be called by the decorated component. (See 'Hooks' for the specs). It will return a function that wraps a Component, Element or string.
Usage:
// es6
const Enhanced = listNodeHooks({})(Component);
// es7
@listNodeHooks({})
Will be called after the List has mounted (componentDidMount) or when it receives new children after the instance method 'flush' has been called.
Will be called after the order of the children has changed. 'x', 'y', 'w', 'h' represent the amount of pixels left, top, width and height has changed since the node's last position. Cool for animation!
Will be called when chilren are added to the list.
Will be called when chilren are deleted. The callback must be called after DOM manipulation in order for the list component to know that the elements are ready to be unmounted.
Will be called when props of children changed.
Enables you to delete all children in the list without unmouting. By default the hook 'itemsDelete' will be called, unless you provide a custom hook for it.
Example:
import listNodeHooks from 'list-node-hooks';
import React, { Component } from 'react';
const hooks = {
itemsFlush(nodes, cb) {
// do something with these nodes...
// invoke callback to continue unmouting
cb();
}
};
const List = listNodeHooks(hooks)('div');
class App extends Component {
state = {
items: [
{ id: 1, text: 'item1' },
{ id: 2, text: 'item2' },
{ id: 3, text: 'item3' },
{ id: 4, text: 'item4' }
]
};
_flush = () => this.list.flush(() => {
// do something here, like fetching new data
}, 'itemsFlush')
render() {
return (
<div>
<button onClick={this._flush}>Flush</button>
<List ref={c => this.list = c}>
{ this.state.items.map(({ id, text }) => <div key={id}>{text}</div>) }
</List>
</div>
);
}
}
clone this repo, and:
npm install && npm run example
FAQs
A React list component that allows you to manipulate dom-nodes on transitions
We found that list-node-hooks 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.