-
-
Save gaearon/2b1cb46aff83c19a9de97f8652389424 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
const translationFetcher = createFetcher(async (text) => { | |
const res = await fetch(`${API_URL}?key=${API_KEY}&text=${text}&lang=en-ru`); | |
return (await res.json()).text; | |
}); | |
function Translate(props) { | |
if (!props.text) { | |
return null; | |
} | |
return ( | |
<b>{translationFetcher.read(props.text)}</b> | |
); | |
} | |
export default class App extends PureComponent { | |
state = { | |
input: 'hello', | |
}; | |
render() { | |
return ( | |
<> | |
<input | |
value={this.state.input} | |
onChange={e => this.setState({ input: e.target.value })} | |
/> | |
<br /> | |
<Placeholder | |
delayMs={3000} | |
fallback={<b>translating...</b>} | |
> | |
<Translate text={this.state.input} /> | |
</Placeholder> | |
</> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment