Skip to content

Passing functions as props #921

Closed Answered by JacobWeisenburger
adamzerner asked this question in Q&A
Discussion options

You must be logged in to vote

This is a server side component and you are not passing any functions to the island Counter.

// index.tsx
export default function Home () {
    return <Counter start={3} />
}

If you actually pass a funtion from a server side component to an island, it doesn't work.

// index.tsx
export default function Home () {
    return <Counter fn={() => { }} />
}

// islands/Counter.tsx
export default function Counter ( props: { fn: () => void } ) {
    props.fn() // TypeError: props.fn is not a function
    return <div></div>
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by marvinhagemeister
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants