通用评论

index.js 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import React from "react";
  2. import ReactDOM from "react-dom";
  3. import App, { Editor } from "./App";
  4. import registerServiceWorker from "./registerServiceWorker";
  5. const Index = props => (
  6. <App showAlertComment showAlertReply showAlertFavor showError {...props}>
  7. <Editor maxUpload={9} autoFocus />
  8. </App>
  9. );
  10. /**
  11. * 渲染评论组件
  12. * @param {object} config 编辑器配置
  13. * - {string} id 渲染评论的DOM的 ID
  14. * - {number} type 评论的 type
  15. * - {string} businessId 评论的 businessId
  16. */
  17. function renderComment(config) {
  18. if (!config.id) {
  19. throw new Error("id is required");
  20. }
  21. if (!config.id) {
  22. throw new Error("type is required");
  23. }
  24. if (!config.id) {
  25. throw new Error("businessId is required");
  26. }
  27. const { id, type = 1, businessId = "test" } = config;
  28. ReactDOM.render(
  29. <Index type={type} businessId={businessId} />,
  30. document.getElementById(id)
  31. );
  32. // registerServiceWorker();
  33. }
  34. window.renderComment = renderComment;
  35. // renderComment({
  36. // id: "root-comment",
  37. // type: 1,
  38. // businessId: "test"
  39. // });