S
SolidJS6mo ago
Rinma

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 😵‍💫
3 Replies
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
REEEEE
REEEEE6mo ago
You can use unwrap on the store object before you pass it to parseFile to get the object without the proxy parseFile(unwrap(listState.list))
Rinma
RinmaOP6mo ago
Thanks, unwrap did it 😄 But I think I will also take a look at context, looks also promising
Want results from more Discord servers?
Add your server