score:4
Accepted answer
_toggleModal = () => this.setState({displayModal: !this.state.displayModal})
score:0
constructor (props) {
super(props);
this.state = {
displayModal : false
}
}
render () {
return (
<div style={{visibility : this.state.displayModal === true ? 'visible' : 'hidden'}}>
<p>Pop up: Bet Behind Settings</p>
</div>
<button onClick={this._toggleModal}>CLICK</button>
)
}
_toggleModal = () => {
const current = this.state.displayModal;
this.setState({
displayModal : !current
});
}
score:0
import { Layer, LayerContext } from 'react-layer-stack'
// ... for each `object` in array of `objects`
const modalId = 'DeleteObjectConfirmation' + objects[rowIndex].id
return (
<Cell {...props}>
// the layer definition. The content will show up in the LayerStackMountPoint when `show(modalId)` be fired in LayerContext
<Layer use={[objects[rowIndex], rowIndex]} id={modalId}> {({
hideMe, // alias for `hide(modalId)`
index } // useful to know to set zIndex, for example
, e) => // access to the arguments (click event data in this example)
<Modal onClick={ hideMe } zIndex={(index + 1) * 1000}>
<ConfirmationDialog
title={ 'Delete' }
message={ "You're about to delete to " + '"' + objects[rowIndex].name + '"' }
confirmButton={ <Button type="primary">DELETE</Button> }
onConfirm={ this.handleDeleteObject.bind(this, objects[rowIndex].name, hideMe) } // hide after confirmation
close={ hideMe } />
</Modal> }
</Layer>
// this is the toggle for Layer with `id === modalId` can be defined everywhere in the components tree
<LayerContext id={ modalId }> {({showMe}) => // showMe is alias for `show(modalId)`
<div style={styles.iconOverlay} onClick={ (e) => showMe(e) }> // additional arguments can be passed (like event)
<Icon type="trash" />
</div> }
</LayerContext>
</Cell>)
// ...
score:1
render() {
var returnIt;
if (this.state.hide) {
returnIt = null;
} else {
returnIt = (
<div style={{visibility : this.state.displayModal}}>
<p>Pop up: Bet Behind Settings</p>
</div>
<button onClick={this._openModal}>CLICK</button>
)
}
return (returnIt);
}
Source: stackoverflow.com
Related Query
- How to make reactstrap modal open or close from parent component
- Open modal from other component in ReactJS
- Open modal from another component click in react js
- Open a modal from a component
- I have my modal component in a different file and I'm trying to open it from another component
- How to open Modal from another component in hooks?
- How can I open a rect-bootstrap modal dialog from another Component
- how can i open a modal from other component in react js functional component react-modal
- How I can open a Modal from another component in React
- ReactJS - Can I open open a Modal from different component
- Open the modal from different component in react
- How to open child component modal from parent by using its key in ReactJs
- failes to open modal component from another component
- React Material UI open modal from within autocomplete lose focus
- React js: Open same modal from different components
- React: How to close a modal from child opened from parent component
- Modal component renders Twice on open
- Open file dialog from React Component using Electron
- React opening react-bootstrap modal in content component from sidebar
- Formik Form Not submitting from Modal Component
- How to open Materialize confirmation modal when deleting something from a database
- React: Closing Modal in Child Component from Parent
- Get modal to fire from parent component
- How can I set up a react modal to open from anywhere in the app?
- React - How to make a modal component that I can call from anywhere?
- React component modal is open at load and never closes
- How to show and hide a Modal in child component from Parent component?
- How can I open Material UI Modal from parent component?
- Modal Component - How to include and open/close from another component
- React: Trigger a function from React Modal component
More Query from same tag
- How to recreate nginx's try_files in Play Framework for hosting React site
- Unable to deploy application on heroku
- Whenever I Put the payment page on my app, it goes blank on ReactJS
- Why doesn't React provide a transpiler?
- useEffect with hook gives me a warning mesage
- why does this error occur during fetch data from the backend
- Highlight searched text inside the table
- React Bootstrap Table - Trying To Fill Page With Equal Column Width
- Showing 'undefined%' in the graph if data does not exist
- Is there a way I can overwrite the colour the Material UI Icons npm package provides in React?
- React Router typescript Property 'redirectUrl' does not exist on type '{}'
- ReactJS className not being applied to component
- Performing a mysql query from node/express server using ? placeholder getting syntax error | npm mysql package
- GraphQL query to filter GraphCMS posts
- How can i pass a boolean state in reactjs with typescript
- Event target comes back as null when I try to read it after uploading a file
- How to write Mozilla specific CSS using withStyles
- Footer has weird whitespace under it
- How can you make a createRef/useRef not target the last value. But rather go to where its suppose to
- Dynamically set defaultChecked with value of setState within data map with react hooks
- React's useMemo method resulting in invalid hook call
- Loop through an array in React with pause in between the iterations
- Transitioning CSS background on React component on Button click
- React - How can I fire an Event listener just once?
- How can I manage query parameters that are not always filled?
- Why doesn't react update the style in the setState?
- Prevent URL encoding that is removing equals signs from URL
- How to send props to reactjs when Redirect
- converting time to local timezone not working with moment.js in React
- MUI createTheme in nextjs