Hello Everyone,
In prosemirror, I want to replace after word that we type with a translated text. I have tried writing an InputRule that takes a word and calls the api for translated word. But It’s not working because I believe its asynchronous. Here is the code.
new InputRule(/[a-zA-Z]+\s/i, (state, match, start, end) => {
if (!match[0]) {
return null;
}
// utils.convertText takes a word, calls the api and returns translated word.
utils.convertText(match[0]).then((res) => {
let tr = state.tr.insertText(
res,
start - 1,
end
)
return tr;
})
})
So my question is, how can I replace the words asynchronously ?
Thank you.