I am new to React and javascript want to create a link with name "Browse" which when clicked should take file as input , i got many answers to do it inside class component in React, how can i do it in function component . I tried:
<div>
<br /><span>{i18n.gettext('- or - ')}</span>
<input id='logo-input' ref='logoInput' type='file' onChange={onFileSelected} type='hidden' />
<a href='' onClick={handleBrowse}>{ i18n.gettext('Browse')}</a>
<br />
</div>
handleBrowse function:
const handleBrowse = function(e) {
e.preventDefault();
this.refs.logoInput.click();
};
onFileSelected function:
const onFileSelected = function (e) {
const file = e.dataTransfer ? e.dataTransfer.files[0] : e.currentTarget.files[0];
handleFileSelection(file);
};
when i do it , i get error as:
Stateless function components cannot have refs
I understood that function component cannot have refs, how can i implement this then