HankCa
HankCa

Reputation: 9629

Dynamic iframes in React web app

I asked this as part of a larger question at https://softwareengineering.stackexchange.com/questions/373520/help-defining-architecture-async-messaging-web-app-as-portal-in-web-page. Though with no responses I thought I'd reduce the complexity of the main part of the question to a pure technical one.

I'd like to have one or more web-apps as 'portal's within an outer web app. In HTML5 this could be achieved with <iframe. However the solution I'm desiring is more dynamic than this with the internal web-apps not known ahead of time.

Are there any solutions to this problem? I'm happy to consider any options though a React one preferred. Perhaps i'm missing something obvious here.

Upvotes: 0

Views: 5814

Answers (1)

Matthew Barbara
Matthew Barbara

Reputation: 3962

If I understand your question correctly, your problem is quite simple. Does the following make sense to you? if it does not, please let me know.

render() {
   const { iFrameSrc } = this.state
   // if You have the source, return the iframe
   if (iFrameSrc) return <iframe src={iFrameSrc} />

   // if you dont have the source, render default
   return null;
}

Upvotes: 1

Related Questions