This repository has been archived by the owner on Mar 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: React Flyweight (Initial Commit)
- Loading branch information
Showing
7 changed files
with
3,309 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"presets": ["env"], | ||
"plugins": [ | ||
"transform-object-rest-spread", | ||
"transform-react-jsx" | ||
] | ||
} |
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,40 @@ | ||
# react-flyweight | ||
# React Flyweight Container | ||
|
||
Simple, lightweight flyweight container for your react apps. | ||
Clean up those `onClicks`. | ||
|
||
`~1kb`, awesome. | ||
|
||
### Usage | ||
|
||
```bash | ||
npm i --save react-flyweight | ||
``` | ||
|
||
```diff | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import PropTypes from 'prop-types'; | ||
+ import FlyweightContainer from 'react-flyweight'; | ||
|
||
const arr = []; | ||
|
||
- const add = (idToAdd) => { | ||
- arr.push(elData.id); | ||
- } | ||
+ const onClickHandler = (elData) => { | ||
+ // decide what to do on click here | ||
+ if(elData.action === 'add') { arr.push(elData.id); } | ||
+ } | ||
|
||
const App = () => ( | ||
+ <FlyweightContainer onClickDispatcher={onClickHandler}> | ||
- <button onClick={() => add(1);}>Add</button> | ||
- <button onClick={() => add(2);}>Add</button> | ||
+ <button data-action="add" data-id={1}>Add</button> | ||
+ <button data-action="add" data-id={2}>Add</button> | ||
+ </FlyweightContainer> | ||
); | ||
|
||
render(<App />, document.getElementById('root')); | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.