@viktorvojtek/package-info
v1.0.1
Published
The react hook for getting the simple information about package you are curious of.
Downloads
5
Maintainers
Readme
package-info
There could be a moment in working on a project where as a developer you need to maintain your components based on multiple versions of other packages for a lots of reasons.
This package provides a simple hook to get version information about a package you need to know from a package.json file.
Installation
npm install package-info
or
yarn add package-info
Usage
import React from 'react';
// This is the package.json file you want to get information from,
// imported from its path relative to the current file.
import packageJson from './package.json';
import usePackageInfo from 'package-info';
const App = () => {
const {version, name} = usePackageInfo({
packageJsonFile: packageJson,
packageName: 'lodash',
});
if (version === '3.0.0') {
// Render component based on version of lodash 3.0.0
...
}
// Render component based on other versions of lodash
return (
<div>
<h1>Package name: {name}</h1>
<p>Version: {version}</p>
</div>
);
};