#coping value between files
6 messages · Page 1 of 1 (latest)
i need to copy the values of the original link and new link to the file where i do all of the logic
here is the code:
ShortenerForm.tsx
import React, { useState } from 'react';
import ShortenedLink from './ShortenedLink';
const ShortenerForm: React.FC<{ onShorten: (url: string) => void }> = ({ onShorten }) => {
const [url, setUrl] = useState('');
const [ShortenedLink, setShortenedLink] = useState('');
const handleShorten = () => {
onShorten(url);
setUrl('');
};
return (
<div>
<input type="text" value={url} onChange={(e) => setUrl(e.target.value)} />
<input type="text" value={ShortenedLink} onChange={(e) => setShortenedLink(e.target.value)} />
<button onClick={handleShorten}>Shorten</button>
</div>
);
};
export default ShortenerForm;
App.tsx
// src/apps/URLShortener/App.tsx
import React, { useState } from 'react';
import ShortenerForm from './components/ShortenerForm';
import ShortenedLink from './components/ShortenedLink';
let hashMap = new Map<string, string>();
const URLShortenerApp: React.FC = () => {
const [shortenedUrl, setShortenedUrl] = useState<string | null>(null);
const handleShorten = (OriginalLinki:string, ShortenedLinkk:string) => {
let shortenedString = '';
// Generate a random string as the shortened URL (for simulation purposes)
if (ShortenedLink.length === 0) {
shortenedString = Math.random().toString(36).substr(2, 5);
}
else {
shortenedString = ShortenedLinkk;
}
setShortenedUrl(`https://catblik.tech/url/${shortenedString}`);
// Store the mapping between the shortened URL and the original URL
hashMap.set(shortenedString, OriginalLinki);
};
return (
<div>
<h1>URL Shortener</h1>
<ShortenerForm onShorten={()=> handleShorten("","")} />
{shortenedUrl && <ShortenedLink shortenedUrl={shortenedUrl} />}
</div>
);
};
export default URLShortenerApp;
what is your TypeScript question @dull parrot ?
oh i though i deleated the thread but i switched frameworks and the probllem was solved
