sveltestrap
sveltestrap copied to clipboard
Property not updating as expected in Modal
I am a React user, and am having trouble understanding how and when values get updated in svelte. I'm just trying to pass a value into a component updated via a user action. Here are the basics of my code:
<script>
import {Modal, ModalBody} from 'sveltestrap';
let currentPollType = null;
const myPoll = {
type: 1,
// ...
};
const onClickBroadcast = function(e, poll) {
console.log(poll.type);
currentPollType = poll.type;
console.log('currentPollType', currentPollType); // set correctly here
};
</script>
<button
type="button"
class="btn btn-primary btn-sm"
on:click={(e) => onClickBroadcast(e, myPoll)}>
Broadcast
</button>
<Modal isOpen={true} size="lg">
<ModalBody>
{currentPollType}
</ModalBody>
</Modal>
So, what am I doing wrong here? The currentPollType prop is always null in the child component. If I put <PollResponses>
outside the Modal, it updates as expected.
StackOverflow issue: https://stackoverflow.com/q/74868657/173630
Had a similar issue, it was throwing this warning during build.
Was able to fix it; it seems to be working and behaving fine after adding this line to /node_modules/sveltestrap/src/Modal.Svelte but I'm not confident enough to file a PR for it and could use a second opinion or two before doing so.