The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/views/root/BlazeTemplate.tsx

41 lines
1004 B

import { Blaze } from 'meteor/blaze';
import { EJSONable } from 'meteor/ejson';
import { ReactiveDict } from 'meteor/reactive-dict';
import { Template } from 'meteor/templating';
import React, { FC, useEffect, useRef } from 'react';
type BlazeTemplateProps = {
template: keyof typeof Template;
data?: EJSONable;
};
const hiddenStyle = { display: 'none' } as const;
const BlazeTemplate: FC<BlazeTemplateProps> = ({ template, data }) => {
const ref = useRef<HTMLDivElement>(null);
const dataRef = useRef(new ReactiveDict());
useEffect(() => {
if (data) {
dataRef.current.set(data);
}
});
useEffect(() => {
if (!ref.current || !ref.current.parentNode) {
return;
}
const data = dataRef.current;
const view = Blaze.renderWithData(Template[template], () => data.all(), ref.current.parentNode, ref.current);
return (): void => {
Blaze.remove(view);
};
}, [template]);
return <div ref={ref} data-blaze-template style={hiddenStyle} />;
};
export default BlazeTemplate;