0.2.3 • Published 2 years ago

with-data v0.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

with-data

A React higher order component for associating data items with components for use in event handlers for high performance user interfaces.

Install

npm i with-data

or

yarn add with-data

Use

const DataItemButton = withDataItem(
  Button, // <---------- A component to wrap
  ['onClick'] // <------ which event handlers should be wrapped
);

const people = ['Derek', 'Jim', 'Joe', 'Mike'];

const sayName = (name: string) => alert(`Hello, ${name}`);

const App = () => {
  return (
    <div>
      {people.map((person) => (
        <DataItemButton
          dataItem={person} // <------------ associate any data with this component
          onClickDataItem={sayName} // <---- no need for lambda here which would otherwise cause unnecessary rerenders, data item will be passed as the first arg of the handler
        >
          {person}
        </DataItemButton>
      ))}
    </div>
  );
};
0.2.1

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago