const ColumnContext = createContext();
function Cell(props) {
const column = useContext(ColumnContext);
onMount(() => console.log(column)); // logs undefined, expected index
return (
...
);
}
function Row(props) {
const resolved = children(() => props.children);
return (
<div>
<For each={resolved()}>
{(child, index) => (
<ColumnContext.Provider value={index()}>
{child}
</ColumnContext.Provider>
)}
</For>
</div>
);
}
function App() {
return (
<Row>
<Cell>...</Cell>
<Cell>...</Cell>
<Cell>...</Cell>
</Row>
);
}
const ColumnContext = createContext();
function Cell(props) {
const column = useContext(ColumnContext);
onMount(() => console.log(column)); // logs undefined, expected index
return (
...
);
}
function Row(props) {
const resolved = children(() => props.children);
return (
<div>
<For each={resolved()}>
{(child, index) => (
<ColumnContext.Provider value={index()}>
{child}
</ColumnContext.Provider>
)}
</For>
</div>
);
}
function App() {
return (
<Row>
<Cell>...</Cell>
<Cell>...</Cell>
<Cell>...</Cell>
</Row>
);
}