Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Communication between two component in html and react #3

Open
konglx90 opened this issue Feb 1, 2020 · 2 comments
Open

Communication between two component in html and react #3

konglx90 opened this issue Feb 1, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@konglx90
Copy link
Contributor

konglx90 commented Feb 1, 2020

customEvent + web component

@konglx90
Copy link
Contributor Author

konglx90 commented Feb 1, 2020

html:

<xq-button>
   我是按钮
</xq-button>
<script>
const button = document.querySelector('xq-button');
button.addEventListener('xq:click', function() {
  console.log('button click')
});
</script>

react:

import React, { useState, useRef, useEffect } from "react";
import useXqEvent from '@xqui/use-xq-event';
import '@xqui/button';

function ReactXqButtonDemo() {
  const [theme, setTheme] = useState('default');
  const button = useRef();

  useXqEvent(button, [{
    event: 'xq:click',
    handler: function() {
      console.log('click button')
      setTheme('primary')
    }
  }])

  return (
    // @ts-ignore
    <xq-button ref={button} theme={theme}>hhh</xq-button>
  )
}

export default ReactXqButtonDemo;

@konglx90 konglx90 added the documentation Improvements or additions to documentation label Feb 2, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant