-1

I’ve developed a tabbed UI dashboard in Next.js and React, where each new menu item opens in a new tab inside the dashboard panel. I can manage the tab mount state without issues.

However, I’m facing a problem with my <iframe> component: whenever I switch tabs and the component re-renders, the <iframe> reloads its URL. I want the <iframe> to retain its state and not reload when the tab changes or the component re-renders.

How can I prevent the <iframe> from reloading in this scenario?

1
  • 2
    Please provide enough code so others can better understand or reproduce the problem. Commented Sep 27 at 8:46

1 Answer 1

0
function Dashboard() {
  const [activeTab, setActiveTab] = useState('tab1');
  
  return (
    <div>
      <TabNavigation activeTab={activeTab} onTabChange={setActiveTab} />  
      <iframe 
        src="your-url"
        style={{ 
          display: activeTab === 'iframe-tab' ? 'block' : 'none',
          width: '100%',
          height: '500px'
        }}
      /> 
      {activeTab === 'other-tab' && <OtherTabContent />}
    </div>
  );
}
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.