use-rng-emoji v1.0.2
use-rng-emoji
React Hook and wrapper Component that generates a random Emoji
Why ?
Well, uh...React Hooks for the win ! Am I rite ?
This Package exists so that I can study React Hooks, the Hydra pattern and how to publish React Components on NPM.
How do I use it ?
Although it would be more appropriate to ask Why I'm using it, following there is a brief example on how to use the Hook:
import { useRandomEmoji } from 'use-rng-emoji';
function SomeSFC(props) {
const { randomEmoji } = useRandomEmoji();
return (
<p>{randomEmoji}</p>
);
}
Did you know that you can pass to the Hook your very own Math.random-compatible function ? Look at that flexibility !
With Math.random-compatible function I mean a function that somehow returns a number in the range [0, 1) just like Math.random.
import { useRandomEmoji } from 'use-rng-emoji';
//Pretty weak Math.random-compatible function
function myRandomFunction() {
return 0.5;
}
function SomeSFC(props) {
const { randomEmoji } = useRandomEmoji(myRandomFunction);
return (
<p>{randomEmoji}</p>
);
}
This Package follows the Hydra pattern by exposing the Hook itself and a Container Component with a render prop. called... render
You can use the Component like so:
import React from 'react';
import ReactDOM from 'react-dom';
import RandomEmoji from 'use-rng-emoji';
function SomeSFC( { randomEmoji } ) {
return (
<p>{randomEmoji}</p>
);
}
...
ReactDOM.render(
<RandomEmoji render={SomeSFC} />,
entryPoint
);
Limitations
React Hooks are available only on the next version of React and are still an Alpha feature and probably unstable.
This Package uses the powerful render-props package which depends on a more stable release of React, so you might see some Warnings when installing.
There are no tests ! This Package is literally a playground, do not expect much real-world effort !