Wednesday, September 13, 2023
HomeReactInstalled React Application Or Element In Iframe - react-iframe

Installed React Application Or Element In Iframe – react-iframe


The react-iframe part offers a straightforward method to install one more React application or part in an iframe. This opens effective opportunities for make-up, safety, and also seclusion of parts.

Exactly how to utilize it:

1. Set up and also import the part right into your React application.

 # NPM

. $ npm i @uiw/ react-iframe
 import React from 'respond';

. import IFrame from' @uiw/ react-iframe';

2. This is a fast instance to show exactly how you can cover material within the ‘react-iframe’ part:

 export default feature Demonstration() {

.

(

. < IFrame > 
.

right here

.  
.); 
.}

3. The initialContent prop defines the preliminary HTML to be infused right into the structure. Keep in mind: This just occurs when and also will not upgrade also if the prop modifications. By default, it is:

< < html><> < head><>  < body><>  

4. Utilize the mountTarget quality (a CSS selector like #target/. target) to define where within the iframe’s preliminary material your part ought to place.

 export default feature Demonstration() {

.

<> 
 < div design= {{shade:' red >'}<}
<> ReactScript  
.
 
.); 
.}(* )5. The

ref Prop is your secret to accessing the internal << iframe>> DOM node straight. import React, {useEffect, useState, Piece} from ‘respond’; . import IFrame from’ @uiw/ react-iframe’ ;
. export default feature Demonstration() {
. const


= useState( );

. const[iframeRef, setIframeRef] => useState (0);

. useEffect(()= > {

. if (iframeRef) {
. iframeRef.focus (); 
.}

.
<}
<,[count, setCount]); 
. const click =()= > setCount (matter + 1); 
. return( 
. < Piece > 
. < switch>
onClick=
<{click} design= {{screen:' flex'} >
}>. > Click  
.
<< IFrame ref= {(node)= > node & & setIframeRef( node)} > 
. < div > Hello there Globe!  
. > < div design= {<{

.
> {matter}  
.  
.  
<.); 
.}[iframeRef] 6. Required to present a certain link within the

< iframe >(* )? Simply utilize the(* )src prop. import React, {useEffect, useState, Piece}
from' respond'; . import IFrame from' @uiw/ react-iframe';
< . export default feature Demonstration() { . . return ( . < IFrame src =" https://reactscript.com/"/ > .); .} 7. Accessibility the iframe's home window and also paper easily utilizing either the FrameContext.Consumer

 or the

useFrame hook. import React, {useEffect, useState, Piece} from 'respond'; . import IFrame, {FrameContext} from '@uiw/ react-iframe'; . export default feature Demonstration( ){ .
.
(
< . < IFrame > .
< FrameContext.Consumer > . {({ paper, home window}
<)= > {
< . return ( <. << div> > .
< div > Hello there Globe! . .
<) .} <} . . . ); .} 8. You can include material prior to the kids of the structure utilizing the head ( *
) prop.

 const head =( 
.// ... 
. 
)
;
<
. export default feature Demonstration( ){
. >
return(

.
<< IFrame>
head = {
head} > 
. ... 
.  
.); 
.}

Sneak Peek: Download And Install Information: Writer

: 

Live Demonstration


embed-component-in-iframe

:

Sight The Demonstration Download And Install Web Link

: Download And Install The Resource Code Authorities Site

: https://github.com/uiwjs/react-iframe Permit

: MIT

RELATED ARTICLES

Most Popular

Recent Comments