impl ModalState {
pub fn close(&mut self) {
println!("Close modal");
self.open = false;
self.heading.clear();
self.child = None;
}
pub fn open(&mut self, heading: String, element: Element) {
println!("Open modal");
self.open = true;
self.heading = heading;
self.child = Some(element);
}
}
pub fn Modal() -> Element {
let mut modal_state = consume_context::<Signal<ModalState>>();
rsx!(
div { {modal_state().child.unwrap_or(rsx!()) } }
)
}
// calling code.
button {
onclick: move |_| {
modal_state.write().open("Create new project".to_string(), NewProject())
},
"Create a new project"
}
I am having all event listeners work but state updates on child components don't work mounting the component directly somewhere else.
What I am trying to do is render a component in modal (shared state through context) only when a component needs t be opened in modal.