Created
April 25, 2020 11:20
-
-
Save erdemuslu/359db518a97e0d71f0aab3cdd3a21989 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
import { inject } from 'mobx-react'; | |
const Search = ({ updateName, getLyrics }) => { | |
const [value, setValue] = useState({ | |
title: '', | |
artist: '', | |
}); | |
const handleValue = (e) => { | |
setValue({ ...value, [e.target.id]: e.target.value }); | |
}; | |
const handleSubmit = (e) => { | |
e.preventDefault(); | |
getLyrics(value); | |
setValue({ artist: '', title: '' }); | |
}; | |
const handleName = () => { | |
updateName('Cemil'); | |
}; | |
return ( | |
<form | |
onSubmit={handleSubmit} | |
> | |
<input | |
aria-label="artist" | |
id="artist" | |
type="text" | |
placeholder="Sanatci ismini giriniz" | |
onChange={handleValue} | |
value={value.artist} | |
/> | |
<input | |
aria-label="title" | |
id="title" | |
type="text" | |
placeholder="Sarki ismini giriniz" | |
onChange={handleValue} | |
value={value.title} | |
/> | |
<button | |
type="button" | |
onClick={handleName} | |
> | |
Ismi Guncelle | |
</button> | |
<button | |
type="submit" | |
> | |
Ara | |
</button> | |
</form> | |
); | |
}; | |
export default inject((stores) => ({ | |
updateName: stores.Store.updateName, | |
getLyrics: stores.Store.getLyrics, | |
}))(Search); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment