Skip to content

Feat/add NullstackFunctionalComponent type#273

Merged
Mortaro merged 3 commits intonullstack:unstable-nextfrom
mayconfsousa:feat/functional-component-type
Dec 4, 2022
Merged

Feat/add NullstackFunctionalComponent type#273
Mortaro merged 3 commits intonullstack:unstable-nextfrom
mayconfsousa:feat/functional-component-type

Conversation

@mayconfsousa
Copy link
Copy Markdown
Contributor

@mayconfsousa mayconfsousa commented Aug 30, 2022

Usage

import { NullstackClientContext, NullstackFunctionalComponent } from 'nullstack';

interface InputProps {
  label: string;
}

function Input({ label, page }: NullstackClientContext<InputProps>) {
  console.log(page.title);
  return <p>{label}</p>;
}

export default Input as NullstackFunctionalComponent<InputProps>;

@mayconfsousa mayconfsousa changed the title Feat/add FC type Feat/add NullstackFunctionalComponent type Aug 31, 2022
@Mortaro
Copy link
Copy Markdown
Member

Mortaro commented Sep 3, 2022

Nice! @mayconfsousa can you make a proposal for how this would look like if we had two functional components in the same file and one of them is using the other please?

@mayconfsousa
Copy link
Copy Markdown
Contributor Author

mayconfsousa commented Sep 23, 2022

Nice! @mayconfsousa can you make a proposal for how this would look like if we had two functional components in the same file and one of them is using the other please?

Example:

Maybe it's worth to reduce the interface name to something like Nullstack.FC 🤔

import './Home.css';

import Nullstack, { NullstackClientContext, NullstackFunctionalComponent } from 'nullstack';

interface ChildProps {
  label: string;
}

const Child: NullstackFunctionalComponent<ChildProps> = ({ label }: NullstackClientContext<ChildProps>) => {
  return <p>{label}</p>;
};

interface ParentProps {
  label: string;
}

const Parent: NullstackFunctionalComponent<ParentProps> = ({ label }: NullstackClientContext<ParentProps>) => {
  return (
    <div>
      <p>{label}</p>
      <Child label="Child" />
    </div>
  );
};

export default class Home extends Nullstack {
  render() {
    return (
      <div>
        <Parent label="Parent" />
      </div>
    );
  }
}

@mayconfsousa mayconfsousa force-pushed the feat/functional-component-type branch from 253e7d9 to 6fa1fae Compare November 4, 2022 13:21
@Mortaro Mortaro changed the base branch from next to unstable-next December 4, 2022 16:13
@Mortaro Mortaro merged commit 6050e56 into nullstack:unstable-next Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants