In my react application the API sends some javascript function as a string
i.e. export const test=()=>{alert('Function from external source');} export const v=()=>void is sent. now I get it in my react application and as the state changes the component re-renders.
now, how can I call the testfunction in my component atcomponentDidUpdate or any other lifecycle hooks?
- I am using Mobx and an observable variable get loaded by that string and as component re-renders that I can get it via props, so this is why
componentDidUpdatewas my first candidate
API sends some javascript function as a stringone of the worst pattern ever.evalexportdeclarations, there is no way to evaluate the string as is as JavaScript. If you can convert this to something else that you can evaluate withevalornew Function, you could do that, but it's certainly not an ideal approach.