Rinma
Rinma
SSolidJS
Created by Rinma on 6/30/2024 in #support
How to get snapshot value from store
Hi, I currently have the following problem. I try to create a file and need values from a Store for this. Here some code: The store state/list-state.js
import { createStore } from 'solid-js/store';

const [listState, setListState] = createStore({
list: [],
});

export const useListState = () => [listState, setListState];
import { createStore } from 'solid-js/store';

const [listState, setListState] = createStore({
list: [],
});

export const useListState = () => [listState, setListState];
A button components/Actions.jsx
import styles from './Actions.module.css';
import { parseFile } from '../../utils/file';
import { useListState } from '../../state/list-state';

export default function Actions() {
const [listState] = useListState();

function startParsing() {
parseFile(listState.list);
}

return (
<div
class={styles.actions}
onClick={() => {
startParsing();
}}
>
<h1>Generate List</h1>
</div>
);
}
import styles from './Actions.module.css';
import { parseFile } from '../../utils/file';
import { useListState } from '../../state/list-state';

export default function Actions() {
const [listState] = useListState();

function startParsing() {
parseFile(listState.list);
}

return (
<div
class={styles.actions}
onClick={() => {
startParsing();
}}
>
<h1>Generate List</h1>
</div>
);
}
The file parser utils/file.js
export function parseFile(list) {
console.log(list);
console.log(list?.forEach((entry) => entry));

const today = new Date();
const file = `
{
${list?.forEach((entry, index) => `entry: "${entry.url}`)}
}`;
}
export function parseFile(list) {
console.log(list);
console.log(list?.forEach((entry) => entry));

const today = new Date();
const file = `
{
${list?.forEach((entry, index) => `entry: "${entry.url}`)}
}`;
}
The problem now is, that parseFile(listState.list); ends in me getting a Proxy object, that is what my browser console is reporting, instead of the wanted array list. When I try to access it, I only get undefined back. And now I don't understand how to get something like a non-reactive snapshot of the value from the store object, that I can use as a parameter for the parse function. Or what is happening here, why is it undefined 😵‍💫
4 replies