-
-
Notifications
You must be signed in to change notification settings - Fork 148
Implement createPortal API #452
Comments
Likely doable via preact-portal |
This is causing problems when trying to leverage https://ant.design/ |
Also material-ui |
This is #1 on the todo list. |
also in 'reactstrap` (beta)
|
I took a swing at implementing this (very naively), but no success; render fails with If there's anyway to get a stack trace on an undefined tag, that would be helpful, but I assume the only reason that's not happening is because the root of the issue comes from the custom code in preact-compat that I've added. |
When you enable the debug tools you have callback where you can make custom assertions on each |
So actually, quick question: is it only related to Would the same error show up without using the compatibility layer but preact directly? |
@samtheprogram hiya! Mind joining our chat? |
Hey @developit, I've joined under the same username as my GitHub account! |
Also breaks compatibility with searchkit (elasticsearch component library) with the same error of export createPortal not found in react-dom. I assume all use of the Portal API is not currently available |
I was trying to achieve something similar to createPortal using render method. But i am unable to pass context to the child components. Here is what i am doing.. class BaseModal extends Component {
constructor(props) {
super(props);
this.id = (new Date()).getTime() + '';
this.element = '';
}
componentDidMount() {
console.log('In mount');
const { children } = this.props;
this.element = render(<div id={this.id}>{children}</div>, document.getElementById('modal-div'));
}
componentDidUpdate() {
const el = document.getElementById(this.id);
el.parentElement.removeChild(el);
const { children } = this.props;
this.element = render(<div id={this.id}>{children}</div>, document.getElementById('modal-div'));
}
componentWillUnmount() {
console.log('In unmount');
const el = document.getElementById(this.id);
el.parentElement.removeChild(el);
}
render() {
console.log(this.context);
// const childrenWithPrpos = children.map((child, index) => cloneElement(child, this.props));
return '';
}
} class Test extends Component {
render(){
return(<BaseModal>{this.props.children}</BaseModal>)
}
} Here context is not passed to children, as it is not rendered as a child. |
Hey @Kanaye, this works. Thank you for your time. If we can provide props and context to the component which will be mounted somewhere outside our actual app, aren't we achieving everything React.createPortal does? am i missing something? I am trying to understand the portal implementation in react, i've gone through createPortal source code and i wasn't able to understand completely. But the basic idea is, it should work just like any other component inside our app, right? We can even use |
@Madhu0 around 90% of it, yes. They also redirect event bubbling through portal boundaries, which Preact is unlikely to ever do. |
This is causing an issue with react-md,
|
is there any thing we can do while this is not implemented? |
Same issue with react-select
|
If anyone wants to PR the implementation, something like this would work: import { h } from 'preact';
import Portal from 'preact-portal';
export function createPortal(child, container) {
return <Portal into={container}>{child}</Portal>
} |
nevermind, there was a much smaller and simpler way and I've implemented it in #486. If anyone has time to test it out that would be lovely. |
Implement createPortal(). Fixes #452.
I'm getting the same error about 'createPortal' above.
What am I missing? |
https://reactjs.org/docs/portals.html
The text was updated successfully, but these errors were encountered: