Skip to content

Commit a2a2ac9

Browse files
committed
feat: exposed internal cache for dev purpose
1 parent d5ae035 commit a2a2ac9

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

.changeset/olive-seals-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-mqtt-hooks": patch
3+
---
4+
5+
feat: exposed internal cache for dev purpose

example/src/components/demo.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { useState } from "react";
2+
import { _cache } from "react-mqtt-hooks";
23
import SingleTopicCard from "./single-topic-card";
34
import { Button } from "./ui/button";
45

56
export default function Demo() {
67
const [show, setShow] = useState(false);
8+
function printCache() {
9+
console.log(_cache);
10+
}
711
return (
812
<section className="space-y-2">
9-
10-
<p>
11-
Component mount/unmount should get the data from cache.
12-
</p>
13+
<p>Component mount/unmount should get the data from cache.</p>
1314
<Button onClick={() => setShow(!show)} variant="outline" size="lg">
1415
{show ? "Hide" : "Show"}
1516
</Button>
17+
<Button onClick={printCache} size="lg" variant="secondary" className="ml-2">
18+
Print Cache
19+
</Button>
1620

17-
{show && <SingleTopicCard topic="chat/1" />}
21+
{show && <SingleTopicCard topic="chat/3" />}
1822
</section>
1923
);
2024
}

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ import { MqttConnector } from "./contexts/mqtt-connector";
33
import useMqttClient from "./hooks/use-mqtt-client";
44
import useTopic from "./hooks/use-topic";
55
import useTopics from "./hooks/use-topics";
6+
import { MqttCache } from "./internals/mqtt-cache";
67

7-
export { MqttConnector, useMqttClient, useTopic, useTopics };
8+
const _cache = MqttCache.getInstance();
9+
10+
export { _cache, MqttConnector, useMqttClient, useTopic, useTopics };

0 commit comments

Comments
 (0)