A React component for converting temperatures between Celsius and Fahrenheit.
- Introduction
- Installation
- Usage
- Components
- Features
- Props
- Example Usage
- Scripts
- Dependencies
- DevDependencies
- Conclusion
This package provides a TemperatureConverter React component and a custom hook useTemperatureConverter
for handling temperature conversions.
You can install the package via npm:
npm install @mahesh005/temp_conversion
Import the TemperatureConverter component and use it in your React application:
import React from 'react';
import TemperatureConverter from '@mahesh005/temp_conversion';
const App = () => {
return (
<div>
<TemperatureConverter initialCelsius={25} size={2} showRange={true} />
</div>
);
};
export default App;
useTemperatureConverter: Custom hook for managing temperature state and conversion logic.
initialCelsius (number): Initial temperature in Celsius (default: 0).
celsius (number): Current temperature in Celsius. fahrenheit (number): Current temperature in Fahrenheit. setCelsius (function): Function to set the temperature in Celsius. setFahrenheit (function): Function to set the temperature in Fahrenheit.
import React, { useState } from 'react';
import { useTemperatureConverter } from '@mahesh005/temp_conversion';
const CustomComponent = () => {
const { celsius, fahrenheit, setCelsius, setFahrenheit } = useTemperatureConverter(0);
console.log("Celsius :" + celsius,"Fahrenheit: " + fahrenheit)
return (
<div>
<div>
<label>
Celsius:
<input
type="number"
value={celsius}
onChange={(e) => setCelsius(parseFloat(e.target.value))}
/>
</label>
</div>
<div>
<label>
Fahrenheit:
<input
type="number"
value={fahrenheit}
onChange={(e) => setFahrenheit(parseFloat(e.target.value))}
/>
</label>
</div>
</div>
);
};
export default CustomComponent;
TemperatureConverter: React component for temperature conversion UI. useTemperatureConverter: Custom hook for managing temperature state and conversion logic.
Converts temperatures between Celsius and Fahrenheit. Adjustable size and optional temperature range display.
initialCelsius: Initial temperature in Celsius (default: 0). size: Size multiplier for adjusting visual components (default: 1). showRange: Boolean to show/hide temperature range inputs (default: true).
<TemperatureConverter initialCelsius={0} size={1.5} showRange={false} />
start: Starts the development server. build: Builds the production-ready bundle. test: Runs tests. lint: Lints the codebase.
React React DOM
Babel ESLint Jest
This package provides an easy-to-use component for temperature conversion in React applications. It includes adjustable visual components and straightforward temperature input controls.