Skip to content

Instantly share code, notes, and snippets.

@erdemuslu
Created April 25, 2020 11:20
Show Gist options
  • Save erdemuslu/359db518a97e0d71f0aab3cdd3a21989 to your computer and use it in GitHub Desktop.
Save erdemuslu/359db518a97e0d71f0aab3cdd3a21989 to your computer and use it in GitHub Desktop.
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