Gathering detailed insights and metrics for @bluframe/grapple
Gathering detailed insights and metrics for @bluframe/grapple
npm install @bluframe/grapple
Typescript
Module System
Min. Node Version
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
6,031
Last Day
23
Last Week
43
Last Month
152
Last Year
2,604
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
@bluframe/grapple@1.0.1
Unpacked Size
16.15 kB
Size
4.52 kB
File Count
14
Publised On
21 Dec 2023
Cumulative downloads
Total Downloads
Last day
155.6%
23
Compared to previous day
Last week
59.3%
43
Compared to previous week
Last month
20.6%
152
Compared to previous month
Last year
55.3%
2,604
Compared to previous year
30
BluFrame React Hooks is a collection of useful and reusable hooks to enhance your React development experience.
If you are using yarn
:
1yarn add @bluframe/grapple
And if you are using npm
:
1npm i @bluframe/grapple
You can import the hooks individually:
1import usePrevious from "@bluframe/grapple/usePrevious";
Or import multiple hooks at once:
1import { usePrevious, useOnScreen } from "@bluframe/grapple";
Stores the previous value of a constant.
1import usePrevious from "@bluframe/grapple/usePrevious"; 2 3function App() { 4 const [count, setCount] = useState(0); 5 const previousCount = usePrevious(count); 6 7 return ( 8 <div> 9 <p>Current count: {count}</p> 10 <p>Previous count: {previousCount}</p> 11 <button onClick={() => setCount(count + 1)}>Increment</button> 12 </div> 13 ); 14}
Uses IntersectionObserver
and notifies when an element appears on screen.
1import useOnScreen from "@bluframe/grapple/useOnScreen"; 2 3function App() { 4 const [isVisible, ref] = useOnScreen("0px"); 5 6 return ( 7 <div ref={ref}> 8 {isVisible ? "Element is on screen" : "Element is not on screen"} 9 </div> 10 ); 11}
Creates a boolean
value and an easy toggle function.
1import useToggle from "@bluframe/grapple/useToggle"; 2 3function App() { 4 const [isToggled, toggle] = useToggle(false); 5 6 return ( 7 <div> 8 <p>{isToggled ? "Toggled" : "Not Toggled"}</p> 9 <button onClick={toggle}>Toggle</button> 10 </div> 11 ); 12}
Trims text to a maximum number of characters and adds ...
when content exceeds the limit.
1import useTrimText from "@bluframe/grapple/useTrimText"; 2 3function App() { 4 const text = "This is a long text that needs to be trimmed."; 5 const trimmedText = useTrimText(text, 10); 6 7 return <div>{trimmedText}</div>; 8}
Receives Props, transforms them into ComponentProps, and returns a Component with ComponentProps. The hook also provides the ability to control when the component should render and update.
1import prepareComponent from "@bluframe/grapple/prepareComponent"; 2 3function ExampleComponent({ text }) { 4 return <div>{text}</div>; 5} 6 7const usePrepareComponent = (props) => { 8 return { 9 text: props.text.toUpperCase(), 10 }; 11}; 12 13const options = { 14 onlyRenderIf: (props) => props.text.length > 3, 15 onlyUpdate: ["text"], 16}; 17 18const PreparedExampleComponent = prepareComponent(usePrepareComponent, options)( 19 ExampleComponent 20); 21 22function App() { 23 const [text, setText] = useState("Hello"); 24 25 return ( 26 <div> 27 <input value={text} onChange={(e) => setText(e.target.value)} /> 28 <PreparedExampleComponent text={text} /> 29 </div> 30 ); 31}
In this example, prepareComponent
is used to create a new PreparedExampleComponent
. The usePrepareComponent
function transforms the text
prop to uppercase. The options
object controls the rendering and updating behavior:
onlyRenderIf
: Only renders the component if the text
prop has a length greater than 3.onlyUpdate
: Only updates the component if the text
prop changes.The App
component demonstrates how the PreparedExampleComponent
is used in conjunction with an input field.
We welcome contributions to improve BluFrame React Hooks! If you'd like to contribute, please follow these steps:
Please ensure that your code follows our coding style and passes all tests.
BluFrame React Hooks is MIT licensed.
No vulnerabilities found.
No security vulnerabilities found.