bestguy / sveltestrap

Bootstrap 4 & 5 components for Svelte
https://sveltestrap.js.org
MIT License
1.3k stars 180 forks source link

Property not updating as expected in Modal #522

Open nikolas opened 1 year ago

nikolas commented 1 year ago

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

nisten commented 1 year ago

Had a similar issue, it was throwing this warning during build.

Screenshot 2022-11-28 at 2 46 56 PM

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.

Screenshot 2023-01-01 at 2 14 51 PM