how to use compound pattern with dynamic imports nextjs - reactjs

so i was trying to use dynamic imports in nextjs to import a component that uses compound pattern design(Dialog); but i get the following error while trying to use properties of Dialog:
TS2339: Property 'Title' does not exist on type 'ComponentType<{}>'.
  Property 'Title' does not exist on type 'ComponentClass<{}, any>'.
following is the Dialog component implementation that uses compound pattern:
const Dialog = ({children}) => (
<>
<NativeDialog
open={true}
PaperProps={{
sx: {
width: "700px",
borderRadius: "15px",
"#media only screen and (max-width: 720px)": {
width: "100vw",
height: "100vh",
},
},
}}
>
{children}
</NativeDialog>
</>
);
const DialogHeader = () => (
<div className={styles.headerContainer}>
<div style={{marginRight: "37%"}}>
<IconButton>
<Link href="/" passHref>
<CloseIcon/>
</Link>
</IconButton>
</div>
<div>
<TwitterLogo size="S"/>
</div>
</div>
);
const DialogTitle = ({children}) => (
<NativeDialogTitle>
<div className={styles.titleContainer}>{children}</div>
</NativeDialogTitle>
);
const DialogContent = ({children}) => (
<NativeDialogContent>
<div className={styles.formContainer}>{children}</div>
</NativeDialogContent>
);
const DialogActions = ({children}) => (
<NativeDialogActions>
<div className={styles.actionContainer}>{children}</div>
</NativeDialogActions>
);
Dialog.Header = DialogHeader;
Dialog.Title = DialogTitle;
Dialog.Content = DialogContent;
Dialog.Actions = DialogActions;
export default Dialog;
and here is the component that dynamically imports Dialog:
const Dialog = dynamic(
() => import('../../Dialog'),
{loading: () => <Spinner/>}
)
const Signin = ({signinState, setSigninState, handleSignin, setAuth}) =>
(
<>
<Dialog>
<Dialog.Title>
<Dialog.Header/>
<div className={`font font-eb ${styles.header}`}>
Sign in to Twitter
</div>
</Dialog.Title>
<Dialog.Content>
<div className={styles.contentContainer}>
<div className={styles.contentItem}>
<Button className={buttonStyles.whiteButton}>
<ThirdPartyAuth state="in" company="Google"/>
</Button>
</div>
<div className={styles.contentItem}>
<Button className={buttonStyles.whiteButton}>
<ThirdPartyAuth state="in" company="Apple"/>
</Button>
</div>
<div className={styles.contentItem}>
<Divider orientation="horizontal" text="or" width={300}/>
</div>
<div className={styles.contentItem}>
<TextField
sx={{width: 300}}
label={<div className="font">email</div>}
value={signinState.email}
onChange={e => setSigninState(prevState => {
return {...prevState, email: e.target.value}
})}
/>
</div>
<div className={styles.contentItem}>
<TextField
sx={{width: 300}}
label={<div className="font">password</div>}
value={signinState.password}
onChange={e => setSigninState(prevState => {
return {...prevState, password: e.target.value}
})}
/>
</div>
{(signinState.clientError || signinState.serverError) && <div className={styles.contentItem}>
<div className={styles.error + " font font-m"}>
{signinState.clientError ? signinState.clientError : signinState.serverError ? signinState.serverError : ""}
</div>
</div>}
<div className={styles.contentItem}
onClick={() => handleSignin(signinState, setSigninState, setAuth)}>
<Button
className={`
${buttonStyles.blackButton} font font-eb`}
>
Signin
</Button>
</div>
<div className={styles.contentItem}>
<Button
className={`
${buttonStyles.whiteButton} font font-b`}
>
Forgot password?
</Button>
</div>
<div
className={`${
styles.contentItem + " " + styles.help
} font font-m`}
>
Don&apos;t have an account?
<div style={{display: "inline-block"}}>
<Link href="/signup" passHref>
<div className={styles.signup}>Sign up</div>
</Link>
</div>
</div>
</div>
</Dialog.Content>
</Dialog>
</>
);
export default Signin;
using Dialog with regular import expression doesnt create this problem but dynamically importing it does. any thoughts is appreciated.

Related

Passing click function from One component to other component

In React material ui i am having two components where i am calling save function on button click, is it right way or not can anyone suggest the better way:
const callback = {};
return (
<>
{!state?.creditCard?.isSaved ? (
<Paper elevation={4} className={classes.paymentContainer}>
<Box className={classes.subPaymentContainer}>
<Typography className={classes.title}>Card Payment</Typography>
<CardPaymentForm
callback={callback}
validationPassed={() => actionsCollection.booking.saveCard(true, state.creditCard.lastFourDigits)}
formType="profileForm"
/>
<div>
<Button
type="submit"
onClick={(e) => callback.saveCard(e)}
value="SAVE CREDIT CARD"
className={classes.button}
/>
<div style={{ display: "flex", marginTop: 20 }}>
<img className={classes.lockIcon} src={lockIconInfo} alt="" />
<Typography className={classes.paymentInfo}>
<Link href="/terms" target={"_blank"}>
Terms of Payment
</Link>
.
</Typography>
</div>
</div>
</Box>
</Paper>
) : (
<div style={{ height: 373 }}>
<CardStored removeCard={removeCard} />
</div>
)}
</>
);
in CardPayementForm below calling the save function below is the code:
const CardPaymentForm = ({ classes, callback, validationPassed, formType, lastFourDigits }) {
useEffect(() => {
callback.saveCard = (e) => {
e.preventDefault();
=
if (validateForm()) {
=
validationPassed();
}
};
});
}
here without callback how to call save function directly in cardpaymentform, Any help please
I'm not sure this will apply to your problem but if you had a component_a
like
const ComponentA = ({handleClick}) => {
return(
<>
<button onClick(e => handleEvent(e))>
Click here
</button>
</>
}
and a component_b
const ComponentB = () => {
const handleClick = (e) => {
// do something with the event from component a
}
return(
<>
<ComponentA handleClick={handleClick}/>
</>
)
}

react bootstrap offcanvas custom close button

I got offcanvas working on react using bootstrap. Now I want add a custom close button but it doesn't seems to work. Please guide me on what I'm doing wrong.
<Offcanvas
show={show}
placement="bottom"
onHide={handleClose}
{...props}
className={css["offcanvas-bottom"]}
>
<Offcanvas.Header className="p-0">
<button type="button" class="btn-close text-reset new_close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
<div className={css["pop-image"]}>
<Image
src="https://xxxxxxx/2022030117344459.jpg"
fluid
/>
</div>
</Offcanvas.Header>
<Offcanvas.Body>
Some text as placeholder. In real life you can have the elements you
have chosen. Like, text, images, lists, etc.
</Offcanvas.Body>
</Offcanvas>
I used onClick in my custom button. And toggled the state by doing
const toggleOffcanvas = () => setShow(!show)
Example:
function ToggleSidebarOffcanvas(){
const [show, setShow] = useState(false);
const toggleOffcanvas = () => {
setShow(!show);
};
return (
<Button onClick={toggleOffcanvas}>
Menu
<SidebarOffcanvas show={show} toggleOffcanvas={toggleOffcanvas} />
</Button>)
}
function SidebarOffcanvas({ show, toggleOffcanvas }) {
return (
<Offcanvas className="w-25" show={show} scroll={true} backdrop={false}>
<Offcanvas.Header
className="p-0"
style={{
backgroundColor: "#008069",
color: "white",
}}
>
<Offcanvas.Title>
<div
className="d-flex align-items-end w-100 mb-2 lh-1"
>
<div className="p-2" onClick={toggleOffcanvas}>
<FiArrowLeft />
</div>
<h5 className="ms-3">Profile </h5>
</div>
</Offcanvas.Title>
</Offcanvas.Header>
<Offcanvas.Body>
<div >
...
</div>
</Offcanvas.Body>
</Offcanvas>
);
}

findDOMNode is deprecated in StrictMode, Reactjs Modal Component

Reactjs shows this error when i open modal that is from another component
"index.js:1 Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Modal which is inside StrictMode. Instead, add a ref directly to the element you want to reference."
I've tried alot of other solutions but none of them work in my case
my code file:
class Routes extends Component {
componentDidMount() {
console.log('Component did mount!')
}
loginModalRef = ({ handleShow }) => {
this.showModal = handleShow;
}
onLoginClick = () => {
this.showModal();
}
ShopersModalRef = ({ handleShoperShow }) => {
this.showShoperModal = handleShoperShow;
}
onShopersClick = () => {
this.showShoperModal();
}
//ChargeModalRef = ({ handleChargeShow }) => {
// this.showChargeModal = handleChargeShow;
//}
// onChargeClick = () => {
// this.showChargeModal();
// }
render() {
return (
<div>
{/*<chargeFeeModal ref={this.ChargeModalRef}></chargeFeeModal>*/}
<FormModal ref={this.loginModalRef}></FormModal>
<ShopersModal ref={this.ShopersModalRef}></ShopersModal>
<AppBar position="sticky" className="appbar">
<Toolbar className="NavbarTop">
<div className='row w-100'>
<div className="col-4 LogoOrBack">
<section className="leftBox shopname ml-4">
<Typography className="typography">
{Text}
</Typography>
</section>
</div>
<div className="col-4 centered">
<section className="centerBox">
<Typography className="typography">
<b>Stores</b>
</Typography>
</section>
</div>
<div className="col-4 righted">
<section className="rightBox">
<Typography className="typography">
<Button className="primary btn AccountBtn" onClick={this.onLoginClick}>
<img alt="user account avatar" src={require('../../../assets/images/placeholder_account.png')} className="buttonImage" /> Account
</Button>
<Button className="primary btn" onClick={this.onLoginClick}>
<i className="fa fa-cart-plus cart"></i>
</Button>
</Typography>
</section>
</div>
</div>
</Toolbar>
<Toolbar>
<div className='row w-100'>
<div className='col-lg-4'>
{(() => {
//Javascript for changing buttons
switch (history.location.pathname) {
case "/": return <Button onClick={this.onLoginClick} className="primary postalCodeBtn" >
<img alt="home icon" src={require('../../../assets/images/homeicon.png')} className="buttonImage" /> <b>M4b 146, CA</b> <i className="fa fa-chevron-down downIco"></i>
</Button>;
default: return (
<Button onClick={this.onShopersClick} className="primary postalCodeBtn" >
<img alt="home icon" src={require('../../../assets/images/time.png')} className="buttonImage" /> <b style={{ textTransform: 'capitalize' }}>Shoppers Occupied</b>
</Button>
);
}
})()}
</div>
<div className="col-lg-4 centered p-1 pl-4" >
<div className="searchContainer">
<i className="fa fa-search searchIcon"></i>
<input className="searchBox" type="search" name="search" placeholder="Search Stores" />
</div>
</div>
{TabsShowOrNo}
</div>
</Toolbar>
</AppBar>
<AnimatedSwitch
atEnter={{ opacity: 0 }}
atLeave={{ opacity: 0 }}
atActive={{ opacity: 1 }}
className="switch-wrapper"
>
<Route exact path="/" component={HomePage} />
<Route path='/store/orders/' component={OrdersPage} />
<Route path='/store/aisles/' component={AislesPage} />
<Route path="/store/featured" component={SingleStorePage} />
<Route component={NotFound} />
</AnimatedSwitch>
</div >
)
}
}```
any help will be appreciate

React: The onClick nested within a card is not called

I am using react hooks, and I have erased out other functions not associated with the function I am intending to call. The App functions are rendered
function App() {
const memoizedCallback = React.useCallback(() => {
console.log("Click happened");
}, []);
return (
<div className="App">
<ReactMapGl
{...viewport}
mapboxApiAccessToken={accesstoken}
onViewportChange={viewport => {
setviewport(viewport);
}}
>
{details.map(details => (
<Marker
key={details.name}
latitude={details.lat}
longitude={details.long}
>
<button
class="marker-btn"
onClick={e => {
e.preventDefault();
useselectedpark(details);
}}
>
<img src={icon} alt="icon" className="navbar-brand" />
</button>
</Marker>
))}
{selectedpark ? (
<Popup
latitude={selectedpark.lat}
longitude={selectedpark.long}
onClose={() => {
useselectedpark(null);
}}
>
<div>
<Card style={{ width: "18rem" }}>
<Card.Body>
<Card.Title>{selectedpark.name}</Card.Title>
<Card.Text>{selectedpark.postalcode}</Card.Text>
<div>
<Button variant="primary" onClick={memoizedCallback}>
Visit Gallery
</Button>
</div>
</Card.Body>
</Card>
</div>
</Popup>
) : null}
{console.log("in render", details)}
</ReactMapGl>
</div>
);
}
export default App;
the function I am intending to call is memoizedCallback. The function is called in an onClick of a button within a card.
The sequence of events is as such. A popup appears, and the user has an option to click on a button within the card that appears.
Problem: Currently, when the button is clicked right now, the function memoizedCallback is not called.
Why is that so, what did I miss here?

I want to add a "download button on modal carousel using react-images, the button should be available on modal popup

can i add a button as a parameter to the carousel,i tried all possible ways to add a button to this
<div>
<h2>Using with a Lightbox component</h2>
<Gallery photos={photos} onClick={openLightbox} />
<ModalGateway>
{viewerIsOpen ? (
<Modal onClose={closeLightbox}>
<Carousel
currentIndex={currentImage}
views={photos.map(x => ({
...x,
srcset: x.srcSet,
caption: x.title
}))}
/>
</Modal>
) : null}
</ModalGateway>
<div>
<Down />
</div>
</div>
You can create your own component:
const CustomFooter = ({ isModal, currentView }) => isModal && (
<div className="react-images__footer">
<button
className="btn some-stylin"
type="button"
onClick={() => { downloadImage(currentView.src); }}
>
Download
</button>
</div>
);
<ModalGateway>
{modalIsOpen ? (
<Modal onClose={this.toggleGallery}>
<Carousel
views={this.imgs}
currentIndex={currentIndex}
frameProps={{ autoSize: 'height' }}
components={{ Footer: CustomFooter }}
/>
</Modal>
) : null}
</ModalGateway>

Resources