import React from "react";

class App extends React.Component {
state = {
file: null,
base64URL: ""
};

getBase64 = file => {
return new Promise(resolve => {
let fileInfo;
let baseURL = "";
// Make new FileReader
let reader = new FileReader();
// Convert the file to base64 text
reader.readAsDataURL(file);
// on reader load somthing...
reader.onload = () => {
// Make a fileInfo Object
console.log("Called", reader);
baseURL = reader.result;
console.log(baseURL);
resolve(baseURL);
};
console.log(fileInfo);
});
};

handleFileInputChange = e => {
console.log(e.target.files[0]);
let { file } = this.state;
file = e.target.files[0];
this.getBase64(file)
.then(result => {
file["base64"] = result;
console.log("File Is", file);
this.setState({
base64URL: result,
file
});
})
.catch(err => {
console.log(err);
});
_
this.setState({
file: e.target.files[0]
});
};

render() {
return (
<div>
<input type="file" name="file" onChange={this.handleFileInputChange} />
</div>
);
}
}

export default App;_

--

--

import React,{useState, useEffect} from 'react';
function Timer({Min, Sec, onTimeout}) {
const [seconds, setSeconds] = useState(Sec);
const [minutes, setMinutes] = useState(Min);

function updateTime() {
if (minutes === 0 && seconds === 0) {
onTimeout(true);
} else {
if (seconds === 0) {
setMinutes((minutes) => minutes - 1);
setSeconds(59);
} else {
setSeconds((seconds) => seconds - 1);
}
}
}
useEffect(() => {
const token = setTimeout(updateTime, 1000);
return function cleanUp() {
clearTimeout(token);
};
});
return (
<div>
{minutes === 0 && seconds === 0 ? null : (
<h6>
{minutes}:{seconds < 10 ? `0${seconds}` : seconds}
</h6>
)}
</div>
);
}

export default Timer;

--

--

import React, {useState, useEffect} from ‘react’;

function Timer({Min, Sec, onTimeout}) {

const [seconds, setSeconds] = useState(Sec);

const [minutes, setMinutes] = useState(Min);

function updateTime() {

if (minutes === 0 && seconds === 0) {

onTimeout(true);

} else {

if (seconds === 0) {

setMinutes((minutes) => minutes — 1);

setSeconds(59);

} else {

setSeconds((seconds) => seconds — 1);

}

}

}

useEffect(() => {

const token = setTimeout(updateTime, 1000);

return function cleanUp() {

clearTimeout(token);

};

});

return (

<div>

{minutes === 0 && seconds === 0 ? null : (

<h6>

{minutes}:{seconds < 10 ? `0${seconds}` : seconds}

</h6>

)}

</div>

);

}

export default Timer;

--

--