preactjs / signals

Manage state with style in every framework
https://preactjs.com/blog/introducing-signals/
MIT License
3.62k stars 88 forks source link

NO WORKING REACT NATIVE #561

Closed VigilioYonatan closed 2 months ago

VigilioYonatan commented 2 months ago

no print fetch.

import {useSignal} from '@preact/signals-react';
import axios from 'axios';
import {useEffect} from 'react';
function App(): React.JSX.Element {
  const data = useSignal(null);

  useEffect(() => {
    async function fetching(url: string) {
      const result = await axios.get("https://pokeapi.co/api/v2/pokemon");
      data.value = result.data;
    }
    fetching();
  }, []);

  return (
    <SafeAreaView style={{backgroundColor: '#000', flex: 1}}>
      <ScrollView>
        <TouchableOpacity>
          <Text style={{color: '#fff'}}>+1</Text>
        </TouchableOpacity>
        <Text style={{color: '#fff'}}>{JSON.stringify(data.value)}</Text> // no show result api. useState react work.
      </ScrollView>
    </SafeAreaView>
  );
}

export default App;
XantreDev commented 2 months ago

Do you use babel plugin?

VigilioYonatan commented 2 months ago

Do you use babel plugin?

thanks. i fix that. import {useSignal} from '@preact/signals-react/runtime';

SupertigerDev commented 2 weeks ago

For me, it works, but the optimize example doesnt for react native. The Math.random is always ran on value update. Although it could be because im on an older version of react native

import { signal } from "@preact/signals-react";

const count = signal(0);

// Optimized: Will update the text node directly
function Counter() {
    return (
        <p>
            <>Value: {count}</>
            {Math.random()}
        </p>
    );
}