Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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